DEVILofDARKNESS Posted February 25, 2009 Share Posted February 25, 2009 This gives me only the first row, and I guess it should be with foreach, but I have no experience with foreach can someone help me? <?php #leden #gedichten #gedichten / lid #top 10 posters #top 10 categories #... /*DATABASE SETTINGS */ $query = "SELECT COUNT(user_id) FROM users"; $result = mysql_query($query); list($users) = mysql_fetch_row($result); # Number of users $query = "SELECT COUNT(poem_id) FROM poems"; $result = mysql_query($query); list($poems) = mysql_fetch_row($result); # Number of poems $ppu = $poems / $users; # $ppu = $poems per user $query = "SELECT user_name, ammount FROM users ORDER BY ammount DESC LIMIT 0,10"; $result = mysql_query($query); while($topusers = mysql_fetch_array($result)) : # SELECT all users descending with on 1 the user with the most posts. $query = "SELECT p.*, c.* FROM poems p INNER JOIN categories c ON p.category_id = c.category_id ORDER BY c.ammount DESC LIMIT 0,10"; $result = mysql_query($query); list($categories) = array($result); #SELECT all categories descending with on 1 the category with the most posts. ?> <html dir="ltr"> <head> <title>STATISTIEKEN</title> <link href="../../standard.css" type="text/css" rel="stylesheet" /> <link href='dichtkunst.css' type='text/css' rel="stylesheet" /> </head> <body> <table class="look" height="100%" width="100%" border="1"> <tbody> <tr> <td width="10%" height="100%"><iframe class="frames" src="../../functieknoppen/functieknoppendichtkunst.htm" frameborder="0" width="100%" height="100%" scrolling="no"></iframe> </td> <td><center> <table border="0"><tr><td colspan="2"><b>STATISTIEKEN</b></td></tr> <tr><td>Aantal gebruikers:</td><td><b><?php echo $users; ?></b></td></tr> <tr><td>Aantal gedichten:</td><td><b><?php echo $poems; ?></b></td></tr> <tr><td>Aantal gedichten per gebruiker:</td><td><b><?php echo $ppu; ?></b></td></tr> <tr><td>Top 10 gebruikers:</td><td><b><?php {echo "<ul><li>{$topusers['user_name']} : {$topusers['ammount']}</li></ul>"; ?></b></td></tr> </table> </center></td> </tr> </tbody> </table> </body> </html> <?php endwhile; ?> Quote Link to comment Share on other sites More sharing options...
trq Posted February 26, 2009 Share Posted February 26, 2009 Doing it the way you are you would need another while within the one you already have. You might want to look at our UNION/JOINS tutorial on the main site, executing queries within loops is generally not needed and is very inifficient. Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted February 26, 2009 Author Share Posted February 26, 2009 hm didn't find what I was looking for. what I want to know is how I can show the result of my query (the one wich gives me the $topuser) my query is build right, (I'm quit sure) , but how I need to implment it in the html, ??? Quote Link to comment Share on other sites More sharing options...
trq Posted February 26, 2009 Share Posted February 26, 2009 The problem is your using the variable $result twice, once in an outer loop and then again within that loop. Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted February 26, 2009 Author Share Posted February 26, 2009 Ok, I have renamed one, now it gives me an eroor that T_ENDWHILE was unexpected, but I can't see where it went wrong <?php #leden #gedichten #gedichten / lid #top 10 posters #top 10 categories #... /* DATABASE SETTINGS */ $query = "SELECT COUNT(user_id) FROM users"; $result = mysql_query($query); list($users) = mysql_fetch_row($result); # Number of users $query = "SELECT COUNT(poem_id) FROM poems"; $result = mysql_query($query); list($poems) = mysql_fetch_row($result); # Number of poems $ppu = $poems / $users; # $ppu = $poems per user $query = "SELECT user_name, ammount FROM users ORDER BY ammount DESC LIMIT 0,10"; $result = mysql_query($query); while($topusers = mysql_fetch_array($result)) : # SELECT all users descending with on 1 the user with the most posts. $query = "SELECT p.*, c.* FROM poems p INNER JOIN categories c ON p.category_id = c.category_id ORDER BY c.ammount DESC LIMIT 0,10"; $res = mysql_query($query); list($categories) = array($res); #SELECT all categories descending with on 1 the category with the most posts. ?> <html dir="ltr"> <head> <title>STATISTIEKEN</title> <link href="../../standard.css" type="text/css" rel="stylesheet" /> <link href='dichtkunst.css' type='text/css' rel="stylesheet" /> </head> <body> <table class="look" height="100%" width="100%" border="1"> <tbody> <tr> <td width="10%" height="100%"><iframe class="frames" src="../../functieknoppen/functieknoppendichtkunst.htm" frameborder="0" width="100%" height="100%" scrolling="no"></iframe> </td> <td><center> <table border="0"><tr><td colspan="2"><b>STATISTIEKEN</b></td></tr> <tr><td>Aantal gebruikers:</td><td><b><?php echo $users; ?></b></td></tr> <tr><td>Aantal gedichten:</td><td><b><?php echo $poems; ?></b></td></tr> <tr><td>Aantal gedichten per gebruiker:</td><td><b><?php echo $ppu; ?></b></td></tr> <tr><td>Top 10 gebruikers:</td><td><b><?php {echo "<ul><li>{$topusers['user_name']} : {$topusers['ammount']}</li></ul>"; ?></b></td></tr> </table> </center></td> </tr> </tbody> </table> </body> </html> <?php endwhile; ?> Quote Link to comment Share on other sites More sharing options...
cwarn23 Posted February 26, 2009 Share Posted February 26, 2009 Try replacing the while loop with the following: while($topusers = mysql_fetch_array($result)) {} # SELECT all users descending with on 1 the user with the most posts. Not sure what that while loop is ment to do but I believe it was that : symbol after the while loop causing the problem. Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted February 26, 2009 Author Share Posted February 26, 2009 you didn't say anything.... Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted February 27, 2009 Author Share Posted February 27, 2009 no, it was because I forgot to delete a single "{" Ow, it's so stupid that I looked over it... Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted February 28, 2009 Author Share Posted February 28, 2009 Damn, Still doesn't work... it keep giving me only the first row... Can someone explain me how I can show them all? <?php #leden #gedichten #gedichten / lid #top 10 posters #top 10 categories #... /*DATABASE SETTINGS */ $query = "SELECT COUNT(user_id) FROM users"; $result = mysql_query($query); list($users) = mysql_fetch_row($result); # Number of users $query = "SELECT COUNT(poem_id) FROM poems"; $result = mysql_query($query); list($poems) = mysql_fetch_row($result); # Number of poems $ppu = $poems / $users; # $ppu = $poems per user $query = "SELECT user_name, ammount FROM users ORDER BY ammount DESC LIMIT 0,10"; $result = mysql_query($query); while($topusers = mysql_fetch_array($result)) : # SELECT top 10 users descending with on 1 the user with the most posts. $query = "SELECT p.*, c.* FROM poems p INNER JOIN categories c ON p.category_id = c.category_id ORDER BY c.ammount DESC LIMIT 0,10"; $res = mysql_query($query); while($categories = mysql_fetch_array($res)) : #SELECT top 10 categories descending with on 1 the category with the most posts. ?> <html dir="ltr"> <head> <title>STATISTIEKEN</title> <link href="../../standard.css" type="text/css" rel="stylesheet" /> <link href='dichtkunst.css' type='text/css' rel="stylesheet" /> </head> <body> <table class="look" height="100%" width="100%" border="1"> <tbody> <tr> <td width="10%" height="100%"><iframe class="frames" src="../../functieknoppen/functieknoppendichtkunst.htm" frameborder="0" width="100%" height="100%" scrolling="no"></iframe> </td> <td><center> <table border="0"><tr><td colspan="2"><b>STATISTIEKEN</b></td></tr> <tr><td>Aantal gebruikers:</td><td><b><?php echo $users; ?></b></td></tr> <tr><td>Aantal gedichten:</td><td><b><?php echo $poems; ?></b></td></tr> <tr><td>Aantal gedichten per gebruiker:</td><td><b><?php echo $ppu; ?></b></td></tr> <tr><td>Top 10 gebruikers:</td><td><b><?php echo "<ul><li>{$topusers['user_name']} : {$topusers['ammount']}</li></ul>"; ?></b></td></tr> <tr><td>Top 10 categorien:</td><td><b><?php echo "<ul><li>{$categories['category_name']} : {$categories['ammount']}</li></ul>"; ?></b></td></tr> </table> </center></td> </tr> </tbody> </table> </body> </html> <?php endwhile; endwhile; ?> Quote Link to comment Share on other sites More sharing options...
cwarn23 Posted February 28, 2009 Share Posted February 28, 2009 Try this: <?php #leden #gedichten #gedichten / lid #top 10 posters #top 10 categories #... /*DATABASE SETTINGS */ $query = "SELECT COUNT(user_id) FROM users"; $result = mysql_query($query); list($users) = mysql_fetch_row($result); # Number of users $query = "SELECT COUNT(poem_id) FROM poems"; $result = mysql_query($query); list($poems) = mysql_fetch_row($result); # Number of poems $ppu = $poems / $users; # $ppu = $poems per user $query = "SELECT user_name, ammount FROM users ORDER BY ammount DESC LIMIT 0,10"; $result = mysql_query($query); while($topusers = mysql_fetch_array($result)) { # SELECT top 10 users descending with on 1 the user with the most posts. $query = "SELECT p.*, c.* FROM poems p INNER JOIN categories c ON p.category_id = c.category_id ORDER BY c.ammount DESC LIMIT 0,10"; $res = mysql_query($query); while($categories = mysql_fetch_array($res)) { #SELECT top 10 categories descending with on 1 the category with the most posts. ?> <html dir="ltr"> <head> <title>STATISTIEKEN</title> <link href="../../standard.css" type="text/css" rel="stylesheet" /> <link href='dichtkunst.css' type='text/css' rel="stylesheet" /> </head> <body> <table class="look" height="100%" width="100%" border="1"> <tbody> <tr> <td width="10%" height="100%"><iframe class="frames" src="../../functieknoppen/functieknoppendichtkunst.htm" frameborder="0" width="100%" height="100%" scrolling="no"></iframe> </td> <td><center> <table border="0"><tr><td colspan="2"><b>STATISTIEKEN</b></td></tr> <tr><td>Aantal gebruikers:</td><td><b><?php echo $users; ?></b></td></tr> <tr><td>Aantal gedichten:</td><td><b><?php echo $poems; ?></b></td></tr> <tr><td>Aantal gedichten per gebruiker:</td><td><b><?php echo $ppu; ?></b></td></tr> <tr><td>Top 10 gebruikers:</td><td><b><?php echo "<ul><li>{$topusers['user_name']} : {$topusers['ammount']}</li></ul>"; ?></b></td></tr> <tr><td>Top 10 categorien:</td><td><b><?php echo "<ul><li>{$categories['category_name']} : {$categories['ammount']}</li></ul>"; ?></b></td></tr> </table> </center></td> </tr> </tbody> </table> </body> </html> <?php }} ?> See if the old fashion way works. Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted February 28, 2009 Author Share Posted February 28, 2009 It indeed gives me all the records, but not in the way I mentioned it to be, check the page And scroll down... You will know what I mean. Can someone tell me why it is shown that way? Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted February 28, 2009 Author Share Posted February 28, 2009 the link is 4ade.uuuq.com/statistics.php I couldn't modify my previous post.? Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted March 2, 2009 Author Share Posted March 2, 2009 sorry, but can anybody help me? it's quit urgent... Quote Link to comment Share on other sites More sharing options...
cwarn23 Posted March 3, 2009 Share Posted March 3, 2009 sorry, but can anybody help me? it's quit urgent... I just did a test and the reason why the method of while loops you are using isn't working is because you can't have loops inside loops using that method. Below is an example of the bug. <? $i = 1; $a = 5; while ($a <= 10) : $a++; echo"test<br>"; while ($i <= 10) : echo $i."<br>"; $i++; endwhile; endwhile; ?> Depending on what the documentation describes the usage of this style of loop, perhaps is should be reported as a bug under bugs.php.net 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.