Jump to content

Archived

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

NL_Johan_UK

Find row number

Recommended Posts

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

×

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.