jesjen Posted February 16, 2011 Share Posted February 16, 2011 Hi - i need help with the fourth column named "jobnr" it has to be the highest number first and lowest at the bottum of the tabel. I tried different variation like "mysql_query("SELECT * FROM tabel ORDER BY jobnr DESC")" but with no success. I attached a picture og the working script output <html> <head> <meta http-equiv="Content-type" content="text/html; charset=UTF-8"/> </head> <style type="text/css"> .myclass { font-size: 8pt; font-face: Verdana; } </style> <body> <?php // Define variables $host="host"; // Host name $username="user"; // Mysql username $password="password"; // Mysql password $db_name="database"; // Database name $tbl_name="tabel"; // Table name // Connect to server and select databse mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // saetter db udtraek til UTF-8 endcoding mysql_set_charset('utf8'); // henter db data fra tabllen: jobpositons $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); // Define $color=1 $color="1"; echo '<table border=0" bordercolor="#f3f3f3" cellpadding="1" cellspacing="1">'; echo "<tr bgcolor='#00aeef'> <th>Jobtitel</th> <th>Sted</th> <th>Oprettet</th> <th>jobnr</th> </tr>"; // sortere sql db data og indsaetter i html tabel while($rows=mysql_fetch_array($result)) { // If $color==1 table row color = #ffffff if($color==1){ echo "<tr bgcolor='#ffffff'><td class='myclass'>".$rows['Jobtitel']."</td><td class='myclass'>".$rows['Sted']."</td><td class='myclass'>".$rows['oprettet']."</td><td class='myclass' align='right'>".$rows['jobnr']."</td> </tr>"; // Set $color==2, for switching to other color $color="2"; } // When $color not equal 1, use this table row color else { echo "<tr bgcolor='#f3f3f3'> <td class='myclass'>".$rows['Jobtitel']."</td><td class='myclass'>".$rows['Sted']."</td><td class='myclass'>".$rows['oprettet']."</td><td class='myclass' align='right'>".$rows['jobnr']."</td> </tr>"; // Set $color back to 1 $color="1"; } } echo '</table>'; mysql_close(); ?> </body> </html> [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/227848-help-for-sorting-mysql-tabel-result-from-field-named-jobnr-in-decending-ordrer/ Share on other sites More sharing options...
silkfire Posted February 16, 2011 Share Posted February 16, 2011 In your code you didn't write an ORDER BY clause: $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); Quote Link to comment https://forums.phpfreaks.com/topic/227848-help-for-sorting-mysql-tabel-result-from-field-named-jobnr-in-decending-ordrer/#findComment-1174911 Share on other sites More sharing options...
jesjen Posted February 16, 2011 Author Share Posted February 16, 2011 Thanks for the answer, and yes, I need help incorporating the correct switch for it in that line, like similar to EX. "mysql_query("SELECT * FROM tabel ORDER BY jobnr DESC")" $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); sorry for me not explaining me correct in english - I'm danish Quote Link to comment https://forums.phpfreaks.com/topic/227848-help-for-sorting-mysql-tabel-result-from-field-named-jobnr-in-decending-ordrer/#findComment-1174918 Share on other sites More sharing options...
silkfire Posted February 16, 2011 Share Posted February 16, 2011 Does it work now? Quote Link to comment https://forums.phpfreaks.com/topic/227848-help-for-sorting-mysql-tabel-result-from-field-named-jobnr-in-decending-ordrer/#findComment-1174971 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.