I am trying to get the last row of a table that is ordered by "rank" in Ascending order.... How can i do this?
| SitePoint Sponsor |
I am trying to get the last row of a table that is ordered by "rank" in Ascending order.... How can i do this?



Umm... are they in ACS order in your database, or you sort tham that way when you submit the query?
Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.
Exbabylon- Professional Internet Services





sort it by DESC and limit 1.
ck :: bringing chris to the masses.
ok. So i would sort it so that the highest rank would be on top, how do i get that row? Im kinda new to PHP and MySQL



Can you give us an example of say, 5 entries of your database? I'll be happy to write whatever code you need to get going, but I need your table structure first. Honestly I don't see how you can have entries in your database automaticly sorted by ranking... but then again...
Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.
Exbabylon- Professional Internet Services
ok, im not sure if that is possible. But what i had figured is you do:
$result = mysql_query( "SELECT * FROM bz ORDER BY ASC" )
Now im not sure if that would sort it right, but the table name that im working with is "bz". Fields: name, rank, id (auto increment), password.
i need to save the highest "rank" to $lastrank so i can add to it...
keep in mind that im new to MySQL so if it sounds like i dont exactly know what im doing it is prolly cuz i dont....



hhmm. What exactly are you wanting to do? Try to describe it like you would to a non coder... then maybe I'll be able to decifer it. Then again maybe someone else will be able to better decifer what you're looking for.
Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.
Exbabylon- Professional Internet Services
im trying to take the highest "rank" and add 1 to it. And when i did this in ASP, the way i did it was i sorted it in ASC order by rank. and then did objRS.MoveLast
What this is for is a gaming ladder. And when someone joins they become the highest ranked team/player. So i have to take the highest previous rank and add 1 to it



PHP really makes your job quite easyjust use AUO_INCREMENT!
OR... if I'm misunderstanding, which I think I am...
PHP Code:$sql = "SELECT rank FROM $table ORDER BY rank ASC LIMIT 0, 1";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)){
extract();
$rank++;
$sql = "INSERT INTO $table SET rank='$rank'";
if(!mysql_query($sql)){
echo("Error");
}
}
Last edited by exbabylon; Aug 21, 2001 at 20:57.
Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.
Exbabylon- Professional Internet Services
Bookmarks