Bravat Posted January 31, 2011 Share Posted January 31, 2011 Here is the code: <table class="sortable"> <?php while($row = mysql_fetch_array($result)) { $title = $row["Rim"]; $model = $row["model"]; $dimenzija = $row["Dimenzija"]; $ime = $row['name']; $cena = $row['price']; $cena = number_format($cena, 2, ',', '.'); $id = $row['product_id']; if($i == 0) echo "<tr>"; echo "<td>" ?><a href="index.php?route=product/product&product_id=<?php echo $id?>"><?php echo $model ?></a> <?php echo "<br>$dimenzija<br>$ime<br>"; ?> <span style="color: #900; font-weight: bold;"><?php echo $cena . "din"?> </span> <?php echo "</td>"; if(++$i == $max_columns) { echo "</tr>"; $i=0; } }} if($i > 0) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; echo "</tr>"; } $prev = $start - $per_page; $next = $start + $per_page; if (!($start<=0)){ echo "<a href='{$_SERVER['PHP_SELF']}&start=$prev'>Prethodna strana </a>"; } $page = 1; for($x=0;$x<$record_count;$x=$x+$per_page){ if($start != $x){ echo " <a href='{$_SERVER['PHP_SELF']}&start=$x'> $page </a> ";} else{ echo " <a href='{$_SERVER['PHP_SELF']}&start=$x'> <b>$page</b> </a> ";} $page++; } if (!($start>=$record_count - $per_page)){ echo "<a href='{$_SERVER['PHP_SELF']}?route=product/search&start=$next'> Sledeća strana</a>"; } ?> </table> How can i create sorting button? Is it possible to do it without javascript (I am new to PHP and JS is still unknown to me)? Link to comment https://forums.phpfreaks.com/topic/226226-sorting-php-table/ Share on other sites More sharing options...
Lyleyboy Posted January 31, 2011 Share Posted January 31, 2011 Try this. It's JQuery but its so simple... http://tablesorter.com/docs/ Link to comment https://forums.phpfreaks.com/topic/226226-sorting-php-table/#findComment-1167813 Share on other sites More sharing options...
Bravat Posted January 31, 2011 Author Share Posted January 31, 2011 Well for some crazy reason it won't work . I followed instruction but table remain inactive Link to comment https://forums.phpfreaks.com/topic/226226-sorting-php-table/#findComment-1167916 Share on other sites More sharing options...
The Letter E Posted January 31, 2011 Share Posted January 31, 2011 Well for some crazy reason it won't work . I followed instruction but table remain inactive The easiest way to sort without js is to alter your sql query on click. Once you figure that out it's just a few simple js automations to do it without page reload. example: in your table headers give each heading an <a> like, <a href="#?sort=name">Name</a> php: <?php $sort = $_GET['sort']; $sql = "SELECT * FROM myTable SORT BY $sort ASC"; ?> That's the basic idea behind it. Hope this helped. E Link to comment https://forums.phpfreaks.com/topic/226226-sorting-php-table/#findComment-1168065 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.