Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>//Remove the below line from your code</p> <pre><code>$where.=" ORDER BY " . $_GET['orderBy'] . " " . $order; </code></pre> <p>//instead of the code </p> <pre><code>while ($row = mysql_fetch_array($result)) { echo "&lt;tr&gt;"; echo "&lt;td style='text-align:center'&gt;" . $row['articleTitle'] . "&lt;/td&gt;"; echo "&lt;td style='text-align:center'&gt;" . $row['articleSubTitle'] . "&lt;/td&gt;"; echo "&lt;/tr&gt;"; } </code></pre> <p>//Add the below code </p> <pre><code>$orderBy="articleTitle"; if (isset($_GET['orderBy'])) { $orderBy=$_GET['orderBy']; } $j=0; $content=array(); while ($row = mysql_fetch_array($result)) { $content[$j]['articleTitle']=$row['articleTitle']; $content[$j]['articleSubTitle']=$row['articleSubTitle']; $j++; } $content=sortByOneKey($content,$orderBy,$order); foreach ($content as $value){ echo "&lt;tr&gt;"; echo "&lt;td style='text-align:center'&gt;" . $value['articleTitle'] . "&lt;/td&gt;"; echo "&lt;td style='text-align:center'&gt;" . $value['articleSubTitle'] . "&lt;/td&gt;"; echo "&lt;/tr&gt;"; } </code></pre> <p>//Add the below function in your page</p> <pre><code>&lt;?php //this function is for sorting the array by using key value function sortByOneKey(array $array, $key, $asc = 'ASC') { $result = array(); $values = array(); foreach ($array as $id =&gt; $value) { $values[$id] = isset($value[$key]) ? $value[$key] : ''; } if ($asc=="DESC") { arsort($values); } else { asort($values); } foreach ($values as $key =&gt; $value) { $result[$key] = $array[$key]; } return $result; } ?&gt; </code></pre> <p>Hope this will work for you...!!! :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload