I have a table in my database for my website news, but I’d like to sort the news by an index, descending.
For example, I have 3 rows, each with diiferent indexes: 1, 2 and 3. I want to sort my rows descending by the index and display them in this order: 3, 2 and 1.
Here is some code to start with…
<?php
ob_start();
$host="hosty";
$username="usey";
$password="passy";
$db_name="namey";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql = 'SELECT * FROM `tabley`';
$result = mysql_query($sql);
if (!$result)
{
die(mysql_error());
}
while ($row = mysql_fetch_assoc($result))
{
echo 'row...';
}
ob_end_flush();
?>
How do I do this?
1 Answer