Hi there,
I'm brand new to PHP and MySQL and wonder if anyone out there can shed some light on the output I'm getting in combination with the mysql_fetch_array function and a while loop I'm using to build an array from each record. Or maybe give me an alternative way to code what I'm trying to achieve here.
Basically, I'm counting each iteration of the loop and using modulus to determine whether the increment $rcount value is odd or even. The problem is that mysql_fetch_array returns a populated array (db record) and then an array with one element (empty or NULL) before it fetches the next record. So each value of $rcount is always odd when the while loop returns a record.
Here's my code:
<?$rcount = 0;
while ($row = mysql_fetch_array ($result)){
$rcount = $rcount + 1;
if (($rcount%2) == 0){
echo "<tr class=\"colvals2\">\n";
}else{
echo "<tr class=\"colvals\">\n";
}
$rcount++;
echo " <td valign=\"top\" width=\"3%\"><a href=http://www.phpbuilder.com/board/archive/index.php/\"resview.php?id=".$row[0]."\">".$row[0]."</a></td>\n";
}?>
I'm brand new to PHP and MySQL and wonder if anyone out there can shed some light on the output I'm getting in combination with the mysql_fetch_array function and a while loop I'm using to build an array from each record. Or maybe give me an alternative way to code what I'm trying to achieve here.
Basically, I'm counting each iteration of the loop and using modulus to determine whether the increment $rcount value is odd or even. The problem is that mysql_fetch_array returns a populated array (db record) and then an array with one element (empty or NULL) before it fetches the next record. So each value of $rcount is always odd when the while loop returns a record.
Here's my code:
<?$rcount = 0;
while ($row = mysql_fetch_array ($result)){
$rcount = $rcount + 1;
if (($rcount%2) == 0){
echo "<tr class=\"colvals2\">\n";
}else{
echo "<tr class=\"colvals\">\n";
}
$rcount++;
echo " <td valign=\"top\" width=\"3%\"><a href=http://www.phpbuilder.com/board/archive/index.php/\"resview.php?id=".$row[0]."\">".$row[0]."</a></td>\n";
}?>