Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
arghhh! while loop only running once
Old 06-19-2005, 03:39 PM arghhh! while loop only running once
Average Talker

Posts: 15
Trades: 0
Argh, in the below code it would seem that the first while loop is only executing once, despite the query returning two results, and I cannot for the life of me work out why. GRRR
Any help appreciated
PHP Code:
$query "SELECT sectid, name, type, description FROM ".$prefix."_sections;";
$results mysql_query($query);
while(
$rows mysql_fetch_row($results)) {
    
$sectid $rows[0];
    
$sectname $rows[1];
    
$secttype $rows[2];
    
$sectdescript $rows[3];
    echo 
"<li>$sectname</li>\n";
    echo 
"<ul>\n";
    
$query "SELECT forid, name, type, description FROM ".$prefix."_forums WHERE sectid = $sectid";
        
$results mysql_query($query);
        while(
$rows mysql_fetch_row($results)) {
            
$forid $rows[0];
            
$forname $rows[1];
            
$fortype $rows[2];
            
$fordescript $rows[3];
            echo 
"<li><a href='$page?forum=$forid'>$forname</a></li>\n";
        }
        echo 
"</ul>\n";

bennyboywonder is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-19-2005, 04:06 PM
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
I thinkit might be the semi-colon on the query string line - should be....

PHP Code:
$query "SELECT sectid, name, type, description FROM ".$prefix."_sections"
Might work......

Stoot
stoot98 is offline
Reply With Quote
View Public Profile
 
Old 06-19-2005, 04:46 PM
Average Talker

Posts: 15
Trades: 0
thanks, but that seems to make no difference
bennyboywonder is offline
Reply With Quote
View Public Profile
 
Old 06-19-2005, 05:44 PM
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
I think its the second database query, you are overwriting the $results variable that was created from the first query so when you do mysql_fetch_row at the start of the first while loop it doesnt have anymore...

Hope that makes sense.
Stoot
stoot98 is offline
Reply With Quote
View Public Profile
 
Old 06-19-2005, 08:23 PM
metho's Avatar
Ultra Talker

Posts: 481
Location: Gold Coast - Brisbane QLD, Australia
Trades: 0
Don't convert your long vars to short. By assigning them to vars your contradicting the purpose of the loop. I've illustrated below...

PHP Code:
$row_results mysql_fetch_assoc($results);

while(
$row_results mysql_fetch_assoc($results)) {
    echo 
"<li>$row_results['columnName']</li>\n";
    echo 
"<ul>\n";
    
$query "SELECT forid, name, type, description FROM ".$prefix."_forums WHERE sectid = $sectid";
        
$results mysql_query($query);
        while(
$row_results mysql_fetch_assoc($results)) {
          echo 
"<li><a href='$page?forum=$row_results['columnName']'>$row_results['columnName']</a></li>\n";
        }
        echo 
"</ul>\n";

__________________
I do
Please login or register to view this content. Registration is FREE
based.
Spend a lot of time in
Please login or register to view this content. Registration is FREE
.
And
Please login or register to view this content. Registration is FREE
chews up the rest.
metho is offline
Reply With Quote
View Public Profile Visit metho's homepage!
 
Reply     « Reply to arghhh! while loop only running once
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.20866 seconds with 12 queries