four4swords Posted March 6, 2008 Share Posted March 6, 2008 hi, I have this problem here.. I'm trying to order a MySql table in which i have a few entries, I want to make it descend.. so i added DESC to my MySql statement, and vala! it does the trick and orders it by descending order, however .. it seems to cut one of my entries.. ( the highest) out! What's the deal?! Here's my code.. and it should work.. right? <?php $result = mysql_query("SELECT * FROM rpg_user ORDER BY `playerlevel` DESC") or die(mysql_error()); $row = mysql_fetch_array($result); echo "<table border='1' width='90%'>"; echo "<tr> <th>Player</th> <th>Level</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['username']; echo "</td><td>"; echo $row['playerlevel']; echo "</td></tr>"; } echo "</table>"; ?> Andd... Here's my MySql dump -- Table structure for table `rpg_user` -- CREATE TABLE `rpg_user` ( `id` int(25) NOT NULL auto_increment, `username` varchar(50) collate latin1_general_ci NOT NULL, `money` int(255) NOT NULL, `class` varchar(255) collate latin1_general_ci NOT NULL, `element` varchar(50) collate latin1_general_ci NOT NULL, `strength` int(10) NOT NULL, `speed` int(10) NOT NULL, `health` int(10) NOT NULL, `defence` int(10) NOT NULL, `accuracy` int(10) NOT NULL, `magic` int(10) NOT NULL, `magicatk` int(10) NOT NULL, `magicdef` int(10) NOT NULL, `current_strength` varchar(10) collate latin1_general_ci NOT NULL, `current_speed` varchar(10) collate latin1_general_ci NOT NULL, `current_health` varchar(10) collate latin1_general_ci NOT NULL, `current_defence` varchar(10) collate latin1_general_ci NOT NULL, `current_accuracy` varchar(10) collate latin1_general_ci NOT NULL, `current_magic` varchar(10) collate latin1_general_ci NOT NULL, `current_magicatk` varchar(10) collate latin1_general_ci NOT NULL, `current_magicdef` varchar(10) collate latin1_general_ci NOT NULL, `hair` varchar(255) collate latin1_general_ci NOT NULL, `skintone` int(5) NOT NULL, `shirt` varchar(255) collate latin1_general_ci NOT NULL, `eyecolour` varchar(255) collate latin1_general_ci NOT NULL, `pants` varchar(255) collate latin1_general_ci NOT NULL, `skill_mining` tinyint( NOT NULL, `experience` int(20) NOT NULL, `mining_exp` int( NOT NULL, `playerlevel` tinyint(3) NOT NULL, `losts` int(5) NOT NULL, `wins` int(5) NOT NULL, `disconnections` int(11) NOT NULL, `disconnected` varchar(5) collate latin1_general_ci NOT NULL, `upgradepoints` tinyint(4) NOT NULL, `battle_attack` varchar(255) collate latin1_general_ci NOT NULL, `battle_defend` varchar(255) collate latin1_general_ci NOT NULL, `battle_magic` varchar(255) collate latin1_general_ci NOT NULL, `battle_specialtechniques` varchar(255) collate latin1_general_ci NOT NULL, `weapon` varchar(20) collate latin1_general_ci NOT NULL, `shield` varchar(20) collate latin1_general_ci NOT NULL, `armour` varchar(20) collate latin1_general_ci NOT NULL, `helmet` varchar(20) collate latin1_general_ci NOT NULL, `pendant` varchar(20) collate latin1_general_ci NOT NULL, `wristband` varchar(20) collate latin1_general_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=24 ; -- -- Dumping data for table `rpg_user` -- INSERT INTO `rpg_user` VALUES (19, 'Bugs', 20, 'Human', 'Water', 2, 2, 5, 5, 9, 8, 7, 4, '2', '2', '5', '5', '9', 'undefined', '7', '4', 'fade', 1, 'white', 'brown', 'purple', 1, 0, 0, 1, 0, 0, 0, 'false', 0, 'Punch|Kick|Shove|Slap', 'ArmBlock', 'Leer', 'Taunt', 'none', 'none', 'none', 'none', 'none', 'none'); INSERT INTO `rpg_user` VALUES (23, 'four4swords', 20, 'Uchiha', 'Wind', 42, 5, 8, 13, 9, 7, 3, 4, '10', '5', '2', '2', '9', '10', '3', '4', 'sasuke', 3, 'purple', 'blue', 'blue', 5, 197, 273, 9, 30, 67, 18, 'false', 0, 'Punch|Kick|Shove|Slap', 'ArmBlock', 'Leer', 'Taunt', 'Brotherhood', 'none', 'Shirt', 'none', 'none', 'none'); INSERT INTO `rpg_user` VALUES (18, 'MAN', 20, 'Regeneration', 'Fire', 2, 4, 10, 1, 6, 7, 4, 9, '2', '4', '9', '1', '6', '10', '4', '9', 'avatar', 1, 'white', 'black', 'black', 1, 8, 52, 1, 1, 2, 0, 'false', 0, 'Punch|Kick|Shove|Slap', 'ArmBlock', 'Leer', 'Taunt', 'none', 'none', 'none', 'none', 'none', 'none'); Just incase anyone wants to try replicate my situation! Thanks again! Quote Link to comment Share on other sites More sharing options...
aschk Posted March 6, 2008 Share Posted March 6, 2008 Using the SQL purely, i set up a test database using what you provided. I'm getting back 3 results (as expected) in the order you required. The problem is your PHP. You're doing a $row = mysql_fetch_array($result); BEFORE you do your loop. As a result this pulls the first record and sets the set to the next one, where your loop carrys on. Thus remove the line above ^ (line 3) Quote Link to comment Share on other sites More sharing options...
four4swords Posted March 7, 2008 Author Share Posted March 7, 2008 Ohh Thanks!! For the help! I got it now! ;D Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.