Posted By

assaado on 11/19/08


Tagged

mysql php html open programming sorting grid source


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

vali29


Sorting MySQL data in a GRID


 / Published in: PHP
 

Here is a working example on how to sort data in a grid.

  1. <?php
  2. //basic mysql connection, you'd want to use a DB class or something
  3. $connect = @mysql_connect("localhost","username","password") or die("Could not connect to server.");
  4. $db = @mysql_select_db("database") or die(mysql_error());
  5. $query = "SELECT * FROM table";
  6. $result = @mysql_query($query) or die("Could not execute query");
  7. $check = mysql_num_rows($result);
  8. if ($check == 0) {
  9. echo "Table is empty.";
  10. } else {
  11. ?>
  12. <table>
  13. <?php
  14. $i = 1;
  15. while ($row = mysql_fetch_array($result)) {
  16. if ($i == 1) {
  17. ?>
  18. <tr>
  19. <?php
  20. }
  21. ?>
  22. <td><?php echo $row['column']; ?></td>
  23. <?php
  24. if ($i == 7) { /* here we have 7 columns per row, if you want 10 columns just change this value to 10 instead of 7 */
  25. $i = 0;
  26. ?>
  27. </tr>
  28. <?php
  29. }
  30. $i++;
  31. }
  32. ?>
  33. </tr>
  34. </table>
  35. <?php
  36. }
  37. ?>

Report this snippet  

You need to login to post a comment.