Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Posts
    567
    Thanks
    2
    Thanked 4 Times in 4 Posts

    For each using rows

    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.
    Code:
    $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>;
    	next;
    } 
    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?
    Scott Stewart
    Always happy to learn from pros.

  • #2
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    This is for each row in result

    PHP Code:
    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

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Posts
    567
    Thanks
    2
    Thanked 4 Times in 4 Posts
    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.
    Scott Stewart
    Always happy to learn from pros.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •