Zepo. Posted November 25, 2007 Share Posted November 25, 2007 I cant figure out why the second loop doesnt work...... $groups=mysql_query("SELECT id,name,logo,active,priority,created FROM groups WHERE active='1' ORDER BY priority"); while(list($gid,$gname,$glogo,$gactive,$gpriority,$gcreated)=mysql_fetch_row($groups)){ if(isset($glogo)){ $headlogo="<img src='$glogo' border='0'>"; }else{ $headlogo=""; } $out[body].="<center><br /><br />$headlogo<br /><br /> <table width='96%' cellpadding='1' cellspacing='1' bgcolor='#000000' border='0'> <tr> <td width='37%' style='background: #E4E4E4 url($config[bg]) repeat-x;' colspan='6'><SPAN class='headertitle'>$gname</SPAN></td> </tr> <tr> <td width='37%' style='background: #E4E4E4 url($config[bg2]) repeat-x;'><SPAN class='headertitle'> Title</SPAN></td> <td width='37%' style='background: #E4E4E4 url($config[bg2]) repeat-x;'><SPAN class='headertitle'> Game</SPAN></td> <td width='8%' style='background: #E4E4E4 url($config[bg2]) repeat-x;'><center><SPAN class='headertitle'>Join</SPAN></td> <td width='8%' style='background: #E4E4E4 url($config[bg2]) repeat-x;'><center><SPAN class='headertitle'>Rules</SPAN></td> <td width='8%' style='background: #E4E4E4 url($config[bg2]) repeat-x;'><center><SPAN class='headertitle'>Count</SPAN></td> <td width='3%' style='background: #E4E4E4 url($config[bg2]) repeat-x;'><center><SPAN class='headertitle'></SPAN></td> </tr>"; $ladders=mysql_query("SELECT id,name,game,gamelink,group,isteam,active FROM ladders WHERE group='$gid' ORDER BY id"); while(list($id,$name,$game,$gamelink,$group,$isteam,$active)=mysql_fetch_row($ladders)){ $totalteams=mysql_query("SELECT COUNT(*) FROM ladder_$id "); $totalteams=mysql_fetch_array($totalteams); $totalteams="$totalteams[0]"; if ($active == 0) { $light = "<img src='./images/ineligible.png' border='0' alt='Ladder is inactive!'>"; $link = "$name"; }else{ $light = "<img src='./images/eligible.png' border='0' alt'Ladder is active!'>"; $link = "<a href='$config[scripturl]/standings.php?ladder[id]=$id' class='content'>$name</a>"; } $out[body].=" <tr> <td width='30%' style='background: $config[altcolora] repeat-x;'><SPAN class='content'> <a href='$config[scripturl]/standings.php?ladder[id]=$id' class='content'>$name</a></td> <td width='37%' style='background: $config[altcolora] repeat-x;'><SPAN class='content'> <a href='$gamelink' class='content'>$game</a></td> <td width='8%' style='background: $config[altcolora] repeat-x;'><SPAN class='content'><center><a href='./join.php?ladder=$id'>Join!</a></center></td> <td width='8%' style='background: $config[altcolora] repeat-x;'><SPAN class='content'><center><a href='./rules.php?rules[ladderid]=$id'>Rules</a></center></td> <td width='8%' style='background: $config[altcolora] repeat-x;'><SPAN class='content'><center>$totalteams</center></td> <td width='3%' style='background: $config[altcolora] repeat-x;'><SPAN class='content'><center>$light</center></td> </tr>"; } } Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 25, 2007 Share Posted November 25, 2007 When you say it "doesn't work" can you be more specific. What exactly is happening and what exactly do you expect to happen? Also, running looping queries in that manner is VERY inefficient and can bring your server to a crawl. Do one query instead grabbing all the data you need. Quote Link to comment Share on other sites More sharing options...
Zepo. Posted November 25, 2007 Author Share Posted November 25, 2007 I mean that the second loop doesnt pull anything. I tried removing the WHERE group='$gid' but it didnt do any justice. Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 26, 2007 Share Posted November 26, 2007 I mean that the second loop doesnt pull anything. I tried removing the WHERE group='$gid' but it didnt do any justice. And how did you determine that? Just because nothing is displayed on the page tells you nothing about what was or was not returned in the query. You are not checking your queries to check for errors. Try this: $query = "SELECT id,name,game,gamelink,group,isteam,active FROM ladders WHERE group='$gid' ORDER BY id"; $ladders=mysql_query($query) or die (mysql_error()); Well, I still think you shoud pull only 1 query instead of doing looping queries. This one should do for the first two queries: SELECT g.id, g.name, g.logo, g.active, g.priority, g.created, l.game, l.gamelink, l.isteam, l.active FROM groups g LEFT JOIN ladders l ON g.id = l.group WHERE g.active='1' ORDER BY g.priority, g.id Although I would still incorporate the total teams query as well. ANd with a little rewriting you will make the script run exponentially faster. Quote Link to comment Share on other sites More sharing options...
Zepo. Posted November 26, 2007 Author Share Posted November 26, 2007 There is nothing displayed on the page, also that query returns no errors. Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 26, 2007 Share Posted November 26, 2007 Ok, then have you cheked to see how many records, if any, are returned with that query? This is simple debugging techniques. Just take one step at a time and verify what should or should not be happening at every step. Make this modification. <?php $query = "SELECT id,name,game,gamelink,group,isteam,active FROM ladders WHERE group='$gid' ORDER BY id"; $ladders=mysql_query($query); echo "The query: <br />$query<br />returned " . mysql_num_rows($ladders) . " results<br />"; while(list($id,$name,$game,$gamelink,$group,$isteam,$active)=mysql_fetch_row($ladders)){ ?> Now check the queries and their results to see if they make sense. Quote Link to comment Share on other sites More sharing options...
Zepo. Posted November 26, 2007 Author Share Posted November 26, 2007 The query: SELECT id,name,game,gamelink,group,isteam,active FROM ladders WHERE group='7' ORDER BY id returned results Is what was echo'd. Quote Link to comment Share on other sites More sharing options...
Zepo. Posted November 26, 2007 Author Share Posted November 26, 2007 Bump...... Quote Link to comment Share on other sites More sharing options...
Zepo. Posted November 26, 2007 Author Share Posted November 26, 2007 Bump....sorry but i need this fixed...lol and im totally lost. Quote Link to comment Share on other sites More sharing options...
Zepo. Posted November 26, 2007 Author Share Posted November 26, 2007 Bump? Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 26, 2007 Share Posted November 26, 2007 ok post your recent code and explain your objectives.. and the current prob! Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted November 27, 2007 Share Posted November 27, 2007 Instead of echo'ing the query and how many results it returned, why not test the value of mysql_errno() and display mysql_error() if an error occurred? That would be much more descriptive of your problem. Anyways, I'm willing to bet it's because you have a column named group, which is also a MySQL reserved word. Enclose your column and table names in back ticks. P.S. Try pasting your query directly into phpMyAdmin and see what you get. As mjdamato hinted at, this is just simple debugging. You can not debug your application if you can't get it to display meaningful information to you. Quote Link to comment Share on other sites More sharing options...
Zepo. Posted November 27, 2007 Author Share Posted November 27, 2007 roopurt is correct. it was because of the group column. Once i renamed it, it worked. Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.