PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
//This snippet taken from http://www.webcheatsheet.com/php/get_cu ... ge_url.php
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
$current_url=curPageURL( );
if(isset($_GET['order']))
{
if($_GET['order']=='ascending') $order='descending';
else $order='ASC';
}
else $order='ASC';
$sql_query="SELECT * FROM NEWS ORDER BY <<COLUMN NAME YOU WANT TO SORT BY>>".$order;
//RETRIEVE DATA HERE ETC ETC ETC.
echo "<table>
<tr><td><a href=".$current_url."?order=".$order.">TITLE OF COLUMN TO SORT</a></td></tr>
<tr><td>CONTENTS OF COLUMN OF TABLES RETRIEVED FROM DATABASE...</td></tr>
</table>"
mysql_select_db("news", $con);
$result = mysql_query("SELECT * FROM news ORDER BY `id` DESC"); // ORDER BY (COLUMN) (ASC|DESC)
//////////////
mcccy005 I'm pretty sure that the poster doesn't want to change the order dynamically.. anyways
and your code wouldn't even change the order to "DESC", it would always stay "ASC", unless you manually change the url to "ascending" and then it would change it to "descending" which isn't even correct.