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
https://forums.phpfreaks.com/topic/151559-find-the-placement-of-an-entry-in-mysql/
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?

 

 

 

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.