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
Share on other sites

  • 4 weeks later...

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]

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.