I am trying to get the last row of a table that is ordered by "rank" in Ascending order.... How can i do this?
Printable View
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?
sort it by DESC and limit 1.
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...
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.
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 easy :) just 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");
}
}