Jump to content

Whats wrong


desithugg

Recommended Posts

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

[code]<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>[/code]
Link to comment
https://forums.phpfreaks.com/topic/8173-whats-wrong/
Share on other sites

[!--quoteo(post=367732:date=Apr 23 2006, 01:50 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Apr 23 2006, 01:50 PM) [snapback]367732[/snapback][/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
Link to comment
https://forums.phpfreaks.com/topic/8173-whats-wrong/#findComment-30244
Share on other sites

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.