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]

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.