Mutley Posted May 5, 2007 Share Posted May 5, 2007 I have a "next 10" list, which shows the next 10 people in a que, however if I have 50 people and they arn't in the top 10, how do I have it so it says something like: "You are in X place out of 50 people" The data is in a SQL database, I guess I need to count it or something? Table is like this: position_id | user_id Quote Link to comment https://forums.phpfreaks.com/topic/50170-solved-position-in-a-que/ Share on other sites More sharing options...
MadTechie Posted May 5, 2007 Share Posted May 5, 2007 counting is the easy option i assume the "next10" will pass the count from var, it if your on 20 and click next10 it passes either 20 or 30 (depends on your code) then just use the var thats used on the LIMIT + count Quote Link to comment https://forums.phpfreaks.com/topic/50170-solved-position-in-a-que/#findComment-246341 Share on other sites More sharing options...
Mutley Posted May 27, 2007 Author Share Posted May 27, 2007 Could you do an example of the COUNT method please? Quote Link to comment https://forums.phpfreaks.com/topic/50170-solved-position-in-a-que/#findComment-262899 Share on other sites More sharing options...
Trium918 Posted May 27, 2007 Share Posted May 27, 2007 counting is the easy option i assume the "next10" will pass the count from var, it if your on 20 and click next10 it passes either 20 or 30 (depends on your code) then just use the var thats used on the LIMIT + count lol is that you [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/50170-solved-position-in-a-que/#findComment-262906 Share on other sites More sharing options...
Mutley Posted May 28, 2007 Author Share Posted May 28, 2007 Hey... don't go offtopic. Quote Link to comment https://forums.phpfreaks.com/topic/50170-solved-position-in-a-que/#findComment-263174 Share on other sites More sharing options...
MadTechie Posted May 28, 2007 Share Posted May 28, 2007 The easiest route i can think of is somethink like this <?php $cont = true; $UID = 12; //users ID $counter = 0; while($row = mysql_query($result) && $cont) { $counter++; $cont = !($row['userid'] = $UID); } echo "you are position $counter"; ?> the basic logic is, find all in position order. loop until you find that users id. stop their and show the number you counter on route hope that makes sense Quote Link to comment https://forums.phpfreaks.com/topic/50170-solved-position-in-a-que/#findComment-263191 Share on other sites More sharing options...
Mutley Posted May 30, 2007 Author Share Posted May 30, 2007 I get: Warning: Cannot use a scalar value as an array I'm guessing because I need to declare it as an array()? This is what I've done: $result = "SELECT user_id, que FROM users ORDER BY que DESC"; $cont = true; $UID = 1; //users ID $counter = 0; while($row = mysql_query($result) && $cont) { $counter++; $cont = !($row['user_id'] = $UID); $cont = array(); } echo "you are position $counter"; Quote Link to comment https://forums.phpfreaks.com/topic/50170-solved-position-in-a-que/#findComment-265266 Share on other sites More sharing options...
MadTechie Posted May 31, 2007 Share Posted May 31, 2007 humm remove $cont = array(); Quote Link to comment https://forums.phpfreaks.com/topic/50170-solved-position-in-a-que/#findComment-265276 Share on other sites More sharing options...
Mutley Posted May 31, 2007 Author Share Posted May 31, 2007 I tried that but the error repeats it's self infinity amount of times. Quote Link to comment https://forums.phpfreaks.com/topic/50170-solved-position-in-a-que/#findComment-265310 Share on other sites More sharing options...
MadTechie Posted May 31, 2007 Share Posted May 31, 2007 humm try <?php $result = "SELECT user_id, que FROM users ORDER BY que DESC"; $cont = true; $UID = 1; //users ID $counter = 0; $row = array(); while($row = mysql_query($result) && $cont) { $counter++; $cont = !($row['user_id'] = $UID); } echo "you are position $counter"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/50170-solved-position-in-a-que/#findComment-265312 Share on other sites More sharing options...
Mutley Posted May 31, 2007 Author Share Posted May 31, 2007 Same error. Quote Link to comment https://forums.phpfreaks.com/topic/50170-solved-position-in-a-que/#findComment-265432 Share on other sites More sharing options...
MadTechie Posted May 31, 2007 Share Posted May 31, 2007 Oh dumb ass (talking to myself) try while(($row = mysql_fetch_assoc($result)) || $cont) Quote Link to comment https://forums.phpfreaks.com/topic/50170-solved-position-in-a-que/#findComment-265505 Share on other sites More sharing options...
Mutley Posted May 31, 2007 Author Share Posted May 31, 2007 Hehe, I get this error now, my query is definatly right as I use it earlier to select information. Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource Quote Link to comment https://forums.phpfreaks.com/topic/50170-solved-position-in-a-que/#findComment-265523 Share on other sites More sharing options...
MadTechie Posted May 31, 2007 Share Posted May 31, 2007 <?php $sqlq = "SELECT user_id, que FROM users ORDER BY que DESC"; $cont = true; $UID = 1; //users ID $counter = 0; $row = array(); $result= mysql_query($sqlq); while(($row = mysql_fetch_assoc($result)) || $cont) { $counter++; $cont = !($row['user_id'] = $UID); } echo "you are position $counter"; ?> DONE.. now click solved ..... please!! LOL Quote Link to comment https://forums.phpfreaks.com/topic/50170-solved-position-in-a-que/#findComment-265531 Share on other sites More sharing options...
Mutley Posted May 31, 2007 Author Share Posted May 31, 2007 Not yet! It says the person is last in the que everytime, so if I have 9 users, it always says "you are position 9", regardless of where they actually are, tried different IDs too. Thanks alot so far! Quote Link to comment https://forums.phpfreaks.com/topic/50170-solved-position-in-a-que/#findComment-265544 Share on other sites More sharing options...
per1os Posted May 31, 2007 Share Posted May 31, 2007 <?php $sqlq = "SELECT user_id, que FROM users ORDER BY que DESC"; $cont = true; $UID = 1; //users ID $counter = 0; $row = array(); $result= mysql_query($sqlq); while(($row = mysql_fetch_assoc($result))) { $counter++; if ($row['user_id'] == $UID) { break; // kill the loop. } } echo "you are position $counter"; ?> Try that. Oh and btw Quote from: MadTechie on May 05, 2007, 03:50:36 PM counting is the easy option i assume the "next10" will pass the count from var, it if your on 20 and click next10 it passes either 20 or 30 (depends on your code) then just use the var thats used on the LIMIT + count lol is that you The question was never answered. Quote Link to comment https://forums.phpfreaks.com/topic/50170-solved-position-in-a-que/#findComment-265561 Share on other sites More sharing options...
Mutley Posted May 31, 2007 Author Share Posted May 31, 2007 Thanks Frost it works, come in to take MadTechies glory, lol. Thanks alot MadTechie. Quote Link to comment https://forums.phpfreaks.com/topic/50170-solved-position-in-a-que/#findComment-265567 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.