Jump to content


Photo

Whats wrong


  • Please log in to reply
2 replies to this topic

#1 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 23 April 2006 - 12:54 PM

I have a ranking page that ranks users according to levels of their creatures for some reason when i put Order by level DESC the bigger numbers show up at the bottom and when i put Order by level ASC the bigger numbers show up at the top (yes the row level is INT) can someone tell me whats wrong with the query

<table align="center" border="2" cellspacing="0" cellpadding="3" bgcolor=white
;'>
<tr>
<td>Icon</td>
<td>Pokemon</td>
<td>Lv.</td>
<td>Owner</td>
</tr>
<?php
$link = mysql_connect('localhost', 'username', 'password');
if (!$link) {
   die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('tpf');
if (!$db_selected) {
   die('Could not select database: ' . mysql_error());
}
$query = "SELECT * FROM pokemon where slot = '1' ORDER BY 'level' DESC";
$result = mysql_query($query);
if (!$result) {
   die('Query failed: ' . mysql_error());
}
/* fetch rows in reverse order */
for ($i = mysql_num_rows($result) - 1; $i >= 0; $i--) {
   if (!mysql_data_seek($result, $i)) {
       echo "Cannot seek to row $i: " . mysql_error() . "\n";
       continue;
   }

   if (!($row = mysql_fetch_assoc($result))) {
       continue;
   }

   echo "<tr><td><form action='viewpoke.php' method='post'><input readonly type='HIDDEN' name='username' maxlength='500' value='". $row['poke_id'] ."'><INPUT TYPE='image' SRC='/images/icons/". $row['pokemon'] .".png' title='". $row['pokemon'] ."(Lv.". $row['level'] .")' VALUE='Submit'
NAME='Submit'></form></td><td><form action='viewpoke.php' method='post'>
<input readonly type='hidden' name='username' maxlength='500' value='".$row['pokemon'] ."'>
<input type='submit' name='submit' value='".$row['pokemon'] ."'>
</form></td><td><form action='battler.php' method='post'>
<input readonly type='hidden' name='poke_id' maxlength='500' value='".$row['poke_id'] ."'>
<input type='submit' name='submit' value='".$row['level'] ."'>
</form></td><td><form action='statsusername.php' method='post'>
<input readonly type='hidden' name='username' maxlength='500' value='".$row['trainer'] ."'>
<input type='submit' name='submit' value='".$row['trainer'] ."'>
</form></td>";
}

mysql_free_result($result);
?></table>


#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 23 April 2006 - 05:50 PM

You're iterating through the rows backwards, so you're negating whatever order direction you specify in the MySQL query. Skip the entire logic of flippng the rows in PHP -- that's what the direction is for!
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 24 April 2006 - 07:56 PM

[!--quoteo(post=367732:date=Apr 23 2006, 01:50 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Apr 23 2006, 01:50 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
You're iterating through the rows backwards, so you're negating whatever order direction you specify in the MySQL query. Skip the entire logic of flippng the rows in PHP -- that's what the direction is for!
[/quote]

lol noticed the problem it has that thing thats reading it in reverse order




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users