0

I want to display table by default in ascendind order with dynamically changing header.

Here is my code. It is displaying the rows unordered. It should be in ascending at first look and then can change by column.

    $order = (isset($_GET['sortCostCode']) && strcasecmp($_GET['sortCostCode'], 'desc') == 0) ? 'DESC' : 'ASC'; 
    $column = isset($_GET['sortcolumn']) ? $_GET['sortcolumn'] : 'logid';
    $column = isset($_GET['sortcolumn']) ? $_GET['sortcolumn'] : 'prenom';

    $query = "SELECT * FROM `Humeur_log` ORDER BY `$column` $order LIMIT 0,30";
    $result = mysql_query($query) or die(mysql_error());;

    ?>
    <table>
          <tr>
          <th><a href='?sortcolumn=logid&sortCostCode=<?php echo $order == 'DESC' ? 'ASC' : 'DESC'; ?>'>Logid</a></th>
          <th><a href='?sortcolumn=prenom&sortCostCode=<?php echo $order == 'DESC' ? 'ASC' : 'DESC'; ?>'>Prenom</a></th>
          </tr>
    <?php
      while($rows=mysql_fetch_assoc($result))
      {
          echo "<tr>";
          echo "<td>" . $rows['logid'] . "</td>";
          echo "<td>" . $rows['prenom'] . "</td>";
          echo "</tr>";
      }
    ?>
       </table>

Edited by PriteshP23: code

2
Contributors
6
Replies
7
Views
4 Years
Discussion Span
Last Post by PriteshP23
0

It should be in ascending

Ascending by what column? Remove line 3, and adjust logid to the column you want to use for the initial sort.

Edited by pritaeas

0

I want to display table by default in ascendind order with " logid "

0

Its working but it should be in ascending order. For the moment, it is displaying in descending order.

It should be able to change afterwords.

1

The code is fine and the output should be ascending (assuming you removed line 3), unless desc is specified in the url.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.