Reputation: 185
I have serial number (named as srno in my database) as primary key in my database.It is in auto-increment mode. I also have date column in database. For a particular user (say aamir)I want the user's records to displayed in a descending format i.e latest first.
So far I have done this :
<?php
$query1 = "SELECT * FROM table2 WHERE id='{$user}'" ;
$result1=mysql_query($query1,$con);
if (!($result1) )
{
die('Error: ' . mysql_error($con));
}
else
{
$values1= mysql_fetch_array($result1);
}
mysql_close($con);
?>
So I have my entries in values1 . Presently my database looks like this:
Clearly 11,12 and 13 all have entries of user aamir. I want them to be displayed in descending order of their serial number. As of now when I display them them using values1 just for eg:
<label>
<span style="font-weight:bold">Symptoms</span>
<input type="text" class="input_text" value="<?php echo " {$values1['Symptoms']}";?>" readonly>
</label>
This shows me symptoms of srno 12 and not 13.I want 13 then 12 then 11 . Please help
Upvotes: 0
Views: 838
Reputation: 16086
You need to add "order by" in your query, like this-
$query1 = "SELECT * FROM table2 WHERE id='{$user}' order by srno desc" ;
Upvotes: 1