title: sort table with a href link, and store a value in a cookies. Can only use PHP
body: <p>I have a table, like this
  <img src="https://i.stack.imgur.com/m7GdM.png" alt="enter image description here"></p>
  
  <p>The titles are to create a cookie, and store a value like "description", when someone clicks the description title. </p>
  
  <p>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). </p>
  
  <pre><code>&lt;table&gt;
         &lt;th&gt;&lt;a href=&lt;?php setcookie("orderCookie", "id"); $PHP_SELF?&gt;&gt;ID&lt;/th&gt;
         &lt;th&gt;&lt;a href=&lt;?php setcookie("orderCookie", "itemName"); $PHP_SELF?&gt;&gt;Item Name&lt;/th&gt;
         &lt;th&gt;&lt;a href=&lt;?php setcookie("orderCookie", "description"); $PHP_SELF?&gt;&gt;Description&lt;/th&gt;
         &lt;th&gt;&lt;a href=&lt;?php setcookie("orderCookie", "supplierCode"); $PHP_SELF?&gt;&gt;Supplier Code&lt;/th&gt;
         &lt;th&gt;&lt;a href=&lt;?php setcookie("orderCookie", "cost"); $PHP_SELF?&gt;&gt;Cost&lt;/th&gt;
         &lt;th&gt;&lt;a href=&lt;?php setcookie("orderCookie", "price"); $PHP_SELF?&gt;&gt;Selling Price&lt;/th&gt;
         &lt;th&gt;&lt;a href=&lt;?php setcookie("orderCookie", "onHand"); $PHP_SELF?&gt;&gt;Number On Hand&lt;/th&gt;
         &lt;th&gt;&lt;a href=&lt;?php setcookie("orderCookie", "reorderPoint"); $PHP_SELF?&gt;&gt;Reorder Point&lt;/th&gt;
         &lt;th&gt;&lt;a href=&lt;?php setcookie("orderCookie", "backOrder"); $PHP_SELF?&gt;&gt;Back Order&lt;/th&gt;
         &lt;th&gt;&lt;a href=&lt;?php setcookie("orderCookie", "deleted"); $PHP_SELF?&gt;&gt;Delete/Restore&lt;/th&gt;
  </code></pre>
  
  <p>requirement:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>Any suggestions? Thanks!</p>
  
  <p>EDIT:</p>
  
  <pre><code>   &lt;th&gt;&lt;a href="?orderBy=id"&gt;ID&lt;/th&gt;
     &lt;th&gt;&lt;a href="?orderBy=itemName"&gt;Item Name&lt;/th&gt;
     &lt;th&gt;&lt;a href="?orderBy=description"&gt;Description&lt;/th&gt;
     &lt;th&gt;&lt;a href="?orderBy=supplierCode"&gt;Supplier Code&lt;/th&gt;
  
  
  if(isset($_GET['orderBy'])){
     $order = $_GET['orderBy'];
     setcookie("orderCookie", $order); 
     header("Location:view.php");
  }
  </code></pre>