I am having issues with a while loop that draws data out of a mysql database. Essentially, a user searches a string, the string is then compared against of possible names in the db. If a string matches a result from the db, then the row is returned and the information relating to the result is dislayed in its' own div.
Here is the, somewhat faulty code relating to the while loop:
(LOTS OF CODE RELATING TO EVERYTHING ELSE BEFORE THIS)
$tempVar = 0;
while ($data = mysql_fetch_array($data)) {
$lstId = $data['id'];
$lstName = $data['name'];
$lstDesc = $data['description'];
$lstAddress = $data['address'];
$lstArea = $data['area'];
$lstProvince = $data['province'];
$lstPostcode = $data['postcode'];
$lstTel = $data['tel'];
$lstCell = $data['cell'];
$lstFax = $data['fax'];
$lstEmail = $data['email'];
if ($tempVar == 0) {
$pageContent .= '
<div class="searchResultS">
';
}
$pageContent .= '
<div class="searchResult">
<h2>'.$lstName.'</h2>
<div class="bizDesc">
<p>Description: '.$lstDesc.'</p>
</div>
<div class="bizAddr">
<p>Street: '.$lstAddress.'</p>
<p>Town: '.$lstArea.'</p>
<p>Province: '.$lstProvince.'</p>
<p>Post Code: '.$lstPostcode.'</p>
</div>
<div class="bizCont">
<p>Tel: '.$lstTel.'</p>
<p>Cell: '.$lstCell.'</p>
<p>Fax: '.$lstFax.'</p>
<p>eMail: '.$lstEmail.'</p>
</div>
</div>
';
$tempVar ++;
}
if ($anymatches > 0 and count($tempVar) == count($anymatches)) {
$pageContent .= '
<!-- end .searchResultS --></div>
';
}
The problem that I am having, is that when a user searches a string with two or more possible results. It seems as though only the last result is displayed. And not all of the possible results, each in their own containing div. I know for a fact that there are more results, as there is a line generated that displayed the number of mysql rows returned.
Would anyone have a suggestion, or solution for this problem? I assume that something has been left out, but after many hours of trial and error testing, i have come up with no solid reason as to why this behavior currently exists.
Any help what so ever would be greatly appreciated, thank you!