I have a table, like this
The titles are to create a cookie, and store a value like "description", when someone clicks the description title.
This is what I have so far, but it doesn't work. When I check the cookie, it sets to the last setcookie which is "deleted". Nothing happens when I click on other links (except page refresh).
<table>
<th><a href=<?php setcookie("orderCookie", "id"); $PHP_SELF?>>ID</th>
<th><a href=<?php setcookie("orderCookie", "itemName"); $PHP_SELF?>>Item Name</th>
<th><a href=<?php setcookie("orderCookie", "description"); $PHP_SELF?>>Description</th>
<th><a href=<?php setcookie("orderCookie", "supplierCode"); $PHP_SELF?>>Supplier Code</th>
<th><a href=<?php setcookie("orderCookie", "cost"); $PHP_SELF?>>Cost</th>
<th><a href=<?php setcookie("orderCookie", "price"); $PHP_SELF?>>Selling Price</th>
<th><a href=<?php setcookie("orderCookie", "onHand"); $PHP_SELF?>>Number On Hand</th>
<th><a href=<?php setcookie("orderCookie", "reorderPoint"); $PHP_SELF?>>Reorder Point</th>
<th><a href=<?php setcookie("orderCookie", "backOrder"); $PHP_SELF?>>Back Order</th>
<th><a href=<?php setcookie("orderCookie", "deleted"); $PHP_SELF?>>Delete/Restore</th>
requirement:
Make each column header a link. When the user clicks on the link, it redisplays the records sorted in ascending order on that column value. Store the name of the column last sorted on in a cookie, and use this as the default sorting the next time the user calls view.php. That is, this cookie should be used to "preserve" the view, even between sessions.
Any suggestions? Thanks!
EDIT:
<th><a href="?orderBy=id">ID</th>
<th><a href="?orderBy=itemName">Item Name</th>
<th><a href="?orderBy=description">Description</th>
<th><a href="?orderBy=supplierCode">Supplier Code</th>
if(isset($_GET['orderBy'])){
$order = $_GET['orderBy'];
setcookie("orderCookie", $order);
header("Location:view.php");
}