Jump to content

help for sorting mysql tabel result from field named "jobnr" in decending ordrer


jesjen

Recommended Posts

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]

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

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.