JayLewis Posted June 5, 2007 Share Posted June 5, 2007 i want to make all the records be shown in a decending order, i've tried using: $sql = 'SELECT * FROM `repair` ORDER BY `repair` . `id` DESC'; but its not working, any help please? Heres the code: <?php $host="xxxxxx"; // Host name $username="xxxxxxx"; // Mysql username $password="xxxxx"; // Mysql password $db_name="xxxx"; // Database name $tbl_name="xxx"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); ?> <html> <head> <meta http-equiv="Content-Language" content="en-gb"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Search For A Birkenheader</title> </head> <body bgcolor="#0D3C8A"> <?php xxxx // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <html> <head> <meta http-equiv="Content-Language" content="en-gb"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Search For A Birkenheader</title> </head> <body bgcolor="#0D3C8A"> <div align="center"> <table border="1" width="752" height="172" bgcolor="#FFFFFF" bordercolorlight="#000000" bordercolordark="#000000"> <tr> <td height="144" width="742" colspan="9"> <font face="Arial" color="#FFFFFF"> <img border="0" src="banner.jpg" width="742" height="140"></font></td> </tr> <tr> <td height="20" width="13" bgcolor="#1C3867" align="center"> <p align="center"><b><font face="Arial" size="2" color="#FFFFFF">ID</font></b></td> <td height="20" width="104" bgcolor="#1C3867" align="center"> <b><font face="Arial" color="#FFFFFF" size="2"> Contact Name</font></b></td> <td height="20" width="113" bgcolor="#1C3867" align="center"> <b><font face="Arial" color="#FFFFFF" size="2">Contact Number</font></b></td> <td height="20" width="70" bgcolor="#1C3867" align="center"> <b><font face="Arial" color="#FFFFFF" size="2">Make</font></b></td> <td height="20" width="75" bgcolor="#1C3867" align="center"> <b><font face="Arial" color="#FFFFFF" size="2">Model</font></b></td> <td height="20" width="89" bgcolor="#1C3867" align="center"> <b><font face="Arial" color="#FFFFFF" size="2">IMEI</font></b></td> <td height="20" width="136" bgcolor="#1C3867" align="center"> <b><font face="Arial" color="#FFFFFF" size="2">Fault</font></b></td> <td height="20" width="44" bgcolor="#1C3867" align="center"> <b><font face="Arial" color="#FFFFFF" size="2">Price</font></b></td> <td height="20" width="50" bgcolor="#1C3867" align="center"> <b><font face="Arial" size="2" color="#FFFFFF">Update</font></b></td></tr> <?php while($rows=mysql_fetch_array($result)) { ?> <tr> <td height="20" width="13" bgcolor="#1C3867" align="center"> <p align="center"><font face="Arial" size="2" color="#FFFFFF"> <a href="reciept.php?id=<? echo $rows['id']; ?>" style="text-decoration: none"> <font color="#FFFFFF"><? echo $rows['id']; ?></font></a> </font></td> <td height="20" width="104" bgcolor="#1C3867" align="center"> <font face="Arial" color="#FFFFFF" size="2"><? echo $rows['name']; ?></font></td> <td height="20" width="113" bgcolor="#1C3867" align="center"> <font color="#FFFFFF" face="Arial" size="2"> <? echo $rows['number']; ?></font></td> <td height="20" width="70" bgcolor="#1C3867" align="center"> <font face="Arial" color="#FFFFFF" size="2"><? echo $rows['make']; ?></font></td> <td height="20" width="75" bgcolor="#1C3867" align="center"> <font face="Arial" color="#FFFFFF" size="2"><? echo $rows['model']; ?></font></td> <td height="20" width="89" bgcolor="#1C3867" align="center"> <font face="Arial" color="#FFFFFF" size="2"><? echo $rows['imei']; ?></font></td> <td height="20" width="136" bgcolor="#1C3867" align="center"> <font face="Arial" color="#FFFFFF" size="2"><? echo $rows['fault']; ?></font></td> <td height="20" width="44" bgcolor="#1C3867" align="center"> <font face="Arial" color="#FFFFFF" size="2"><? echo $rows['price']; ?></font></td> <td height="20" width="50" bgcolor="#1C3867" align="center"> <font face="Arial" size="2" color="#FFFFFF"> <a href="update.php?id=<? echo $rows['id']; ?>" style="text-decoration: none"> <font color="#FFFFFF">Edit</font></a></font></td></tr> <? } mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/54286-desc-records/ Share on other sites More sharing options...
Yesideez Posted June 5, 2007 Share Posted June 5, 2007 Try this: $sql ="SELECT * FROM `repair` ORDER BY `id` DESC"; Quote Link to comment https://forums.phpfreaks.com/topic/54286-desc-records/#findComment-268375 Share on other sites More sharing options...
taith Posted June 5, 2007 Share Posted June 5, 2007 a) you dont have any DESC in there... b) you dont need to connect to the same database twice... Quote Link to comment https://forums.phpfreaks.com/topic/54286-desc-records/#findComment-268378 Share on other sites More sharing options...
JayLewis Posted June 5, 2007 Author Share Posted June 5, 2007 Nope, still not workin :| Quote Link to comment https://forums.phpfreaks.com/topic/54286-desc-records/#findComment-268379 Share on other sites More sharing options...
zell11 Posted June 5, 2007 Share Posted June 5, 2007 yeah desc should work $sql = "SELECT * FROM repair ORDER BY id DESC;"; if that doesn't work then maybe 1. you are overwritting it somewhere before you excute ot. 2. are you sure it's ID you want to sort by and that yu are thinking it hasn't worked due to it still not being in any noticeable order Quote Link to comment https://forums.phpfreaks.com/topic/54286-desc-records/#findComment-268393 Share on other sites More sharing options...
JayLewis Posted June 5, 2007 Author Share Posted June 5, 2007 Yer mate, its deffo ID i need it sorting by... its starting to do my nut in! Quote Link to comment https://forums.phpfreaks.com/topic/54286-desc-records/#findComment-268409 Share on other sites More sharing options...
Yesideez Posted June 5, 2007 Share Posted June 5, 2007 Is the field to sort by in the table definitely called `id`? What data are you getting from the query, if any? Quote Link to comment https://forums.phpfreaks.com/topic/54286-desc-records/#findComment-268413 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.