From: [EMAIL PROTECTED]
Subject: problem with a while loop
Date: May 6, 2004 11:25:28 AM EDT
To: [EMAIL PROTECTED]Hey everybody!
I am new to php (and mySQL) and I am working on a php page that links up to a mySQL database. My current code works up to a point, BUT what happens is that I try to have a while loop and check a variable with an inner while loop but it only catches after the first complete cycle.
Basically, some producers will only call up one row, but you always get 2 at the minimum with this code below. I have tried lots of different things which all lead to the second row endlessly repeating or the page not loading at all.
Any ideas? Please email me directly since I am on the digest. Thanks Jessica
(Also, I am new to this list and if this email is in the wrong format I apologize.)
CODE :
<?
$query = "select * from wine where REGION like 'California' order by PRODUCE,DESCRIPT,VINTAGE";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo "<p>Number of wines found: ".$num_results."</p>";
$i =0;
while ($i < $num_results) {$row = mysql_fetch_array($result);
$producer = $row["PRODUCE"];
echo "<table width=\"400\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" bgcolor=\"#ffffcc\"><tr bgcolor=\"#FFFFFF\"><td colspan=\"4\" class=\"bigtext\">";
echo stripslashes($row["PRODUCE"]);
echo "</td></tr>";
$color = "#ffffcc";
echo "<tr bgcolor=$color><td width=\"50\">";
// id number
echo stripslashes($row["INVID"]);
echo "</td><td>"; // vintage
echo stripslashes($row["VINTAGE"]);
echo " ";
// description
echo stripslashes($row["DESCRIPT"]);
echo " "; // bottle size
if ($row["BOTSIZE"] != "750ml"){
echo "<span class=\"bottlesize_sm\">";
echo stripslashes($row["BOTSIZE"]);
echo "</span>";
}
if ($row["NOTES"] != ""){
echo "<br><i>";
echo stripslashes($row["NOTES"]);
echo "</i>";
}
echo "</td>";
// list price
echo "<td align=\"right\" width=\"60\">";
echo stripslashes($row["WINENUM"]);
echo "</td>";
// sale price
echo "<td align=\"right\" width=\"60\">";
echo stripslashes($row["SALEPRICE"]);
echo "</td>";
while ( $producer == $row["PRODUCE"]) {
if ($color == "#ccdd99")
$color = "#ffffcc";
else
$color = "#ccdd99";
$row = mysql_fetch_array($result);
echo "<tr bgcolor=$color><td width=\"50\">";
// id number
echo stripslashes($row["INVID"]);
echo "</td><td>";
// vintage
echo stripslashes($row["VINTAGE"]);
echo " ";
// description
echo stripslashes($row["DESCRIPT"]);
echo " "; // bottle size
if ($row["BOTSIZE"] != "750ml"){
echo "<span class=\"bottlesize_sm\">";
echo stripslashes($row["BOTSIZE"]);
echo "</span>";
}
if ($row["NOTES"] != ""){
echo "<br><i>";
echo stripslashes($row["NOTES"]);
echo "</i>";
}
echo "</td>";
// list price
echo "<td align=\"right\" width=\"60\">";
echo stripslashes($row["WINENUM"]);
echo "</td>";
// sale price
echo "<td align=\"right\" width=\"60\">";
echo stripslashes($row["SALEPRICE"]);
echo "</td>";
++$i;
}
echo "</tr></table><p> </p>";
++$i;
}
?>