hello all. i have this code...
<?php
$query= "SELECT * FROM table";
$result=mysql_query($query) or die(mysql_error());
$num_rows = mysql_num_rows($result);
if($num_rows > 0)
{
echo "<table>";
while($row = mysql_fetch_array($result))
{
echo "<td>" . $row['data'] . "," . "</td>";
}
echo "</table>";
}
?>
lets say it is displaying from 5 records, it is displaying this way:
data1, data2, data3, data4, data5,
and i'd like it to be displayed without the comma following the last record and WITH an "&" preceding the last record in this way:
data1, data2, data3, data4, & data5
any ideas? i was told to do this...
"Maintain a counter in the while() loop that counts how many records have been outputted so far. Then, use an if() condition to check if the current count is one behind the total number of rows that your query returned (i.e. you're on the last row right now). If so, output the '&' separator. If not, output a comma instead."
...but i can't figure out how to accomplish this. can anyone provide me with an example of what i should be doing? thanks in advance.