DEVILofDARKNESS Posted March 7, 2009 Share Posted March 7, 2009 If I open this code in my webbrowser it always get stuck. :S all the other pages don't it did work until I added $cattop['ammount'] <?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, ( SELECT count( * ) + 1 FROM users b WHERE a.ammount < b.ammount ) AS rank FROM users a ORDER BY rank LIMIT 0 , 10 "; $ress = mysql_query($query); while($usertop = mysql_fetch_array($ress)) { $query = " SELECT category_name, ammount, ( SELECT count( * ) + 1 FROM categories b WHERE a.ammount < b.ammount ) AS rank FROM categories a ORDER BY rank LIMIT 0 , 10 "; $res = mysql_query($query); while($cattop = mysql_fetch_array($res)) { ?> <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 "{$usertop['rank']} | {$usertop['user_name']} | {$usertop['ammount']}"; ?> </b></td></tr> <tr><td>Top 10 categorien:</td><td><b><?php echo "{$cattop['rank']} | {$cattop['category_name']} | {$cattop['ammount']}"; ?></b></td></tr> </table> <?php } } ?> </center></td> </tr> </tbody> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/148371-stats-prob/ Share on other sites More sharing options...
redarrow Posted March 7, 2009 Share Posted March 7, 2009 is this suppose to be this $ppu = $poems / $users; to $ppu = ($poems / $users); look up mysql join the two query's look very un neat. Quote Link to comment https://forums.phpfreaks.com/topic/148371-stats-prob/#findComment-778953 Share on other sites More sharing options...
DEVILofDARKNESS Posted March 7, 2009 Author Share Posted March 7, 2009 Why would that be a problem ? in all the previous versions of that page it worked well. I tried it but still the browser doens't react anymore... Quote Link to comment https://forums.phpfreaks.com/topic/148371-stats-prob/#findComment-778959 Share on other sites More sharing options...
redarrow Posted March 7, 2009 Share Posted March 7, 2009 post the problem big mouth. i was showing you how to group variables, when being used via a maths statement that all. Quote Link to comment https://forums.phpfreaks.com/topic/148371-stats-prob/#findComment-778963 Share on other sites More sharing options...
DEVILofDARKNESS Posted March 7, 2009 Author Share Posted March 7, 2009 sorry I'm just getting irritated about that st*pid bug. it wasn't the meaning to react that way on u , The problem is just if I use code 1 for the site (without the cattegories) it works fast if I use code 2 with the catteogries, the browser get stuck and I have to end the proces. I want to know what the source from that bug is and I wished somebody could help me. code 1: <?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, ( SELECT count( * ) + 1 FROM users b WHERE a.ammount < b.ammount ) AS rank FROM users a ORDER BY rank LIMIT 0 , 10 "; $ress = mysql_query($query); while($usertop = mysql_fetch_array($ress)) { ?> <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 "{$usertop['rank']} | {$usertop['user_name']} | {$usertop['ammount']}"; ?> </b></td></tr> </table> <?php } ?> </center></td> </tr> </tbody> </table> </body> </html> code 2: <?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, ( SELECT count( * ) + 1 FROM users b WHERE a.ammount < b.ammount ) AS rank FROM users a ORDER BY rank LIMIT 0 , 10 "; $ress = mysql_query($query); while($usertop = mysql_fetch_array($ress)) { $query = " SELECT category_name, ammount, ( SELECT count( * ) + 1 FROM categories b WHERE a.ammount < b.ammount ) AS rank FROM categories a ORDER BY rank LIMIT 0 , 10 "; $res = mysql_query($query); while($cattop = mysql_fetch_array($res)) { ?> <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 "{$usertop['rank']} | {$usertop['user_name']} | {$usertop['ammount']}"; ?> </b></td></tr> <tr><td>Top 10 categorien:</td><td><b><?php echo "{$cattop['rank']} | {$cattop['category_name']} | {$cattop['ammount']}"; ?></b></td></tr> </table> <?php } } ?> </center></td> </tr> </tbody> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/148371-stats-prob/#findComment-778967 Share on other sites More sharing options...
redarrow Posted March 7, 2009 Share Posted March 7, 2009 so this is wrong i guess you need a join i guess correct. <?php $query = " SELECT user_name, ammount, ( SELECT count( * ) + 1 FROM users b WHERE a.ammount < b.ammount ) AS rank FROM users a ORDER BY rank LIMIT 0 , 10 "; $ress = mysql_query($query); ?> Quote Link to comment https://forums.phpfreaks.com/topic/148371-stats-prob/#findComment-778970 Share on other sites More sharing options...
redarrow Posted March 7, 2009 Share Posted March 7, 2009 does this do anythink might not just a go sorry no good at joins. <?php $query = " SELECT b.user_name, a.ammount, ( SELECT count( * ) + 1 FROM a.users , b.user_name WHERE a.ammount < b.ammount ) AS rank ORDER BY rank LIMIT 0 , 10 "; $ress = mysql_query($query); ?> Quote Link to comment https://forums.phpfreaks.com/topic/148371-stats-prob/#findComment-778975 Share on other sites More sharing options...
DEVILofDARKNESS Posted March 7, 2009 Author Share Posted March 7, 2009 With that part nothing was wrong, it works well, it doens't work anymore when I add the while(...) from the categories. Quote Link to comment https://forums.phpfreaks.com/topic/148371-stats-prob/#findComment-778978 Share on other sites More sharing options...
redarrow Posted March 7, 2009 Share Posted March 7, 2009 sorry your have to wait for a mysql expert, there on here don't worrie. Quote Link to comment https://forums.phpfreaks.com/topic/148371-stats-prob/#findComment-778983 Share on other sites More sharing options...
Stephen68 Posted March 7, 2009 Share Posted March 7, 2009 Might be way off here but do you really need to run that query inside the while loop? <?php $query = " SELECT category_name, ammount, ( SELECT count( * ) + 1 FROM categories b WHERE a.ammount < b.ammount ) AS rank FROM categories a ORDER BY rank LIMIT 0 , 10 "; ?> It doesn't seem to draw any information from the other query (or it seems to me). So your running it every loop of the above while loop when it looks like it doesn't have to (again I maybe way off, if so sorry). Quote Link to comment https://forums.phpfreaks.com/topic/148371-stats-prob/#findComment-778984 Share on other sites More sharing options...
DEVILofDARKNESS Posted March 9, 2009 Author Share Posted March 9, 2009 Okay, lets say it works, I still have one problem. the statistic page generates a page wich lists all top 10 users, but there is one problem. IF you visit the site, you will see it http://4ade.uuuq.com/statistics.php the problem is that I generate a while loop in a table, the while loop orders all the top ten users, and should place them in a next row in the same table, but it generates it in a next row in a new table. how can I solve this? this is the main code: <?php $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, ( SELECT count( * ) + 1 FROM users b WHERE a.ammount < b.ammount ) AS rank FROM users a ORDER BY rank LIMIT 0 , 10 "; $ress = mysql_query($query); while($usertop = mysql_fetch_array($ress)) { ?> <table border="0"><tr><td colspan="2"><b>STATISTICS</b></td></tr> <tr><td>Ammount of users:</td><td><b><?php echo $users; ?></b></td></tr> <tr><td>Ammount of poems:</td><td><b><?php echo $poems; ?></b></td></tr> <tr><td>Ammount poems / user:</td><td><b><?php echo $ppu; ?></b></td></tr> <tr><td>Top 10 users:</td><td><b><?php echo "{$usertop['rank']} | {$usertop['user_name']} | {$usertop['ammount']}"; ?> </b></td></tr> </table><?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/148371-stats-prob/#findComment-780571 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.