Jump to content

[SOLVED] Position in a que


Mutley

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/50170-solved-position-in-a-que/
Share on other sites

  • 4 weeks later...

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

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";

 

 

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";
?>

<?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

<?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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.