Jump to content

Recommended Posts

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();
?>

Link to comment
https://forums.phpfreaks.com/topic/54286-desc-records/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/54286-desc-records/#findComment-268393
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.