Jump to content


Photo

Find row number


  • Please log in to reply
2 replies to this topic

#1 NL_Johan_UK

NL_Johan_UK
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 29 March 2003 - 05:41 PM

Hey everybody!

Maybe someone can help with the following...

I have a table with player names and their scores. To display the ranking I select names and scores and sort by scores desc.
Now I can while-loop my way through the whole list. No problems.. BUT:

Now I want to find only one persons position in the rankings table.

Imaginary Query:
SELECT row_number, names, scores FROM thetable WHERE name=\'$name\' ORDER BY scores desc

echo hey dude you are $row_number i nthe rankings!

How can I get this number? Do i need to make a temp field named ranking or something? Can I auto increment this temp field?

Id like to do this on the database side so i dont have to pull all data through the pipe for just one dude...

The scores change so often I dont want to save their positions in a field.

If I understand correctly, I think I need an inverse of mysql_data_seek. So instead of giving the pointer and getting the data, I need to give the data (name) and get the pointer (position in table).

Is this possible?

Cheers....

#2 vhkristof

vhkristof
  • Members
  • PipPip
  • Member
  • 11 posts
  • LocationAchel, Limburg, Belgium

Posted 30 March 2003 - 08:42 AM

Well,

I don\'t know if this will work, but I know that in Oracle you have
a statement called ROWID...so this would be like

SELECT    ROWID AS \'rank\', column1, column2

FROM       table

WHERE     rank = 2

I don\'t know if this will work ..., let me know

#3 DocSeuss

DocSeuss
  • Members
  • PipPipPip
  • Advanced Member
  • 73 posts
  • LocationTexas, USA

Posted 30 March 2003 - 11:53 PM

auto increment was only intended to \"automatically\" assign a unique identifier for a new row. If it is important to your project that all of the entries have a field where each one is identified sequencially? You will have to do that manualy with the code. Maybe if you tell us why the holes are causeing you grief we can suggest a different way of doing things.
"Unlimited budget? Great, for $5,000,0000 we will run your ad banner for one year"  ----Rasmus Lerdorf




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users