I was just kindly helped to get the rows in a table to display using ORDER BY. Then I realized I also want to click the same link to decrement if desired. I tried to set up a conditional, but it's not working as I expected:
<?php
$orderBy = array('type', 'description', 'recorded_date', 'added_date');
$order = 'type';
if (isset($_GET['orderBy']) && in_array($_GET['orderBy'], $orderBy)) {
$order = $_GET['orderBy'];
}
$sql="SELECT * FROM $tbl_name ORDER BY " .$order;
?>
<table>
<tr>
<th>
<?php
if($order == 'type'){
?>
<a href="?orderBy=type_dec">Type:</a>
<?php
} else{
?>
<a href="?orderBy=type">Type:</a>
<?php
}
?>
<a href="?orderBy=type">Type:</a>
</th>
<th>
Description:
</th>
<th>
<a href="?orderBy=recorded_date">Recorded Date:</a>
</th>
<th>
<a href="?orderBy=added_date">Added Date:</a>
</th>
</tr>
I know I don't have the full code, but I was surprised to see that even as it is, the "type" link is showing up twice in the above example. I thought one or the other would show up depending on the value of $order.
Also, i have a feeling that the way I'm trying to achieve this with the decrementing could be done in a much better way. Please feel free to share that way!