Jump to content

ORDER BY name DESC LIMIT 0,1 NOT WORKING RIGHT


confused and dazed
 Share

Recommended Posts

Hello internet,

 

I am using the following calls to get an ordered list of largest to smallest info of all that row's data:

*NOTE: there are only 6 entries in mydatabase with grp='c'

 

$result = mysql_query("SELECT * FROM mydatabase WHERE grp='c' ORDER BY score DESC LIMIT 0,1", $con); $rows = array();while ($row = mysql_fetch_assoc($result))...... more code to place data into a specific id to use an onload to populate objects

$result = mysql_query("SELECT * FROM mydatabase WHERE grp='c' ORDER BY score DESC LIMIT 1,1", $con); $rows = array();while ($row = mysql_fetch_assoc($result))...... more code to place data into a specific id to use an onload to populate objects

$result = mysql_query("SELECT * FROM mydatabase WHERE grp='c' ORDER BY score DESC LIMIT 2,1", $con); $rows = array();while ($row = mysql_fetch_assoc($result))...... more code to place data into a specific id to use an onload to populate objects

$result = mysql_query("SELECT * FROM mydatabase WHERE grp='c' ORDER BY score DESC LIMIT 3,1", $con); $rows = array();while ($row = mysql_fetch_assoc($result))...... more code to place data into a specific id to use an onload to populate objects

$result = mysql_query("SELECT * FROM mydatabase WHERE grp='c' ORDER BY score DESC LIMIT 4,1", $con); $rows = array();while ($row = mysql_fetch_assoc($result))...... more code to place data into a specific id to use an onload to populate objects

$result = mysql_query("SELECT * FROM mydatabase WHERE grp='c' ORDER BY score DESC LIMIT 5,1", $con); $rows = array();while ($row = mysql_fetch_assoc($result))...... more code to place data into a specific id to use an onload to populate objects

 

What ends up happening is that I get a list together but here is what I get

DESC LIMIT 0,1 >>> this produces the second largest score - NOT the largest

DESC LIMIT 1,1 >>> this produces the third largest score

DESC LIMIT 2,1 >>> this produces the fourth largest score

DESC LIMIT 3,1 >>> this produces the fifth largest score

DESC LIMIT 4,1 >>> this produces the sixth largest score

DESC LIMIT 5,1 >>> this produces the LARGEST score - not the smallest

Link to comment
Share on other sites

Good question - There is a good answer.

 

 

I need to have complete control over the names that come out of each individual row. I have it set up on my webpage so a user can click on that name and launch a very specific outcome for the name. Keep in mind that I am using an onload function to populate objects as soon as the webpage loads. This way a user can click on a a name and launch a very specific outcome. Using just one query for this limits the functionality I can place on the button object I have associated with each of the 6 names.

 

 

 

The "DESC LIMIT" seems to sort of work but not the way I want it.

 

 

Link to comment
Share on other sites

I don't see any difference between what you're doing, and doing a single query with a counter to know which row you're processing, where you would do different things based on the row. It's also more efficient to send a single query.

Link to comment
Share on other sites

Concatenate....... Right! Doh...!

 

'name_' . $x

 

So I changed my code to one query call but it still came up with the same problem... I also figured out why this was happening. When I set up score in the database I set it up as a varchar(4). What I dummy I can be sometimes! I changed it to an int(4) and everything is OK!

 

I also went back to my previous version of my code with 6 querys and it worked there as well (having it now as an int)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...