Jump to content

Find the placement of an Entry in MySQL


theflea912

Recommended Posts

The title doesn't really provide enough of a description.  I know PHP well enough that I could select an entry via WHERE and LIMIT clause.  Here is the problem:

 

I have a bunch of entries in a table, sorted by time (ASC so the "winning" time is the first entry).  I need to find a users entry in that list and return its placement.  So if they got 3rd place out of 5 people, it would return a 3, and so on.  I have no idea how to do this.  My first idea was to combine each row into an array, and than do array_search for the ID of the user, but that didn't work.  How would you go about doing this? 

Link to comment
Share on other sites

 

Thanks for the quick response. I edited the SQL from one of the examples to:

$new = "SELECT count(*) AS rank FROM (SELECT * FROM workouts WHERE distance='$distance_of' AND ranked='Yes' > (SELECT * FROM workouts WHERE rowerid='$userid_func' AND distance='$distance_of' AND ranked='Yes') ORDER BY time ASC)AS s";

 

 

When I run it though, I get "Operand should contain 1 column(s)". I do not know SQL really all that well, so can someone explain what is going on?

 

 

 

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.