View Full Version : For each using rows

07-29-2007, 03:12 PM
Couldn't find this in the forum and so new I can't find a way to look it up in the my sql reference manual. I have a number of rows returned and I want to loop through the rows and extract the only item to use in building my menu.

$query = "SELECT itemName AS name FROM menu ORDER BY itemPriority ASC";
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

if (mysql_num_rows($result) > 0) {
// yes
for each row in $result{
echo "<li";
if ($thisPage==name) echo " id=\"currentpage\"";
echo " onclick="menuops(name)>name</li>;
else {
// no
// print status message
echo "No rows found!";

See the for each statement and the use of the field 'name'. I just don't know the syntax. Oh yeah, is mysql case sensitive?

07-29-2007, 07:08 PM
This is for each row in result

if (mysql_num_rows($result) > 0) {
// yes

$numrows = mysql_num_rows($result);

for ($i=1, $i <= $numrows, $i++) {

#dunno below this to many parameters missing :)


But it looks to simple to be true :D

07-30-2007, 07:35 PM
That's what I did but I was thinking there was a better way. Just not really thinking, I guess.

Sorry I put this in the wrong forum.