PHP 在GRID中对MySQL数据进行排序

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 在GRID中对MySQL数据进行排序相关的知识,希望对你有一定的参考价值。

<?php
//basic mysql connection, you'd want to use a DB class or something
  $connect = @mysql_connect("localhost","username","password") or die("Could not connect to server.");
  $db = @mysql_select_db("database") or die(mysql_error());
  $query = "SELECT * FROM table";
  $result = @mysql_query($query) or die("Could not execute query");
  $check = mysql_num_rows($result);
  if ($check == 0) {
    echo "Table is empty.";
  } else {
?>
<table>
<?php
  $i = 1;
  while ($row = mysql_fetch_array($result)) {
    if ($i == 1) {
?>
  <tr>
<?php
    }
?>
    <td><?php echo $row['column']; ?></td>
<?php
    if ($i == 7) { /* here we have 7 columns per row, if you want 10 columns just change this value to 10 instead of 7 */
      $i = 0;
?>
  </tr>
<?php
    }
    $i++;
  }
?>
  </tr>
</table>
<?php
  }
?>

以上是关于PHP 在GRID中对MySQL数据进行排序的主要内容,如果未能解决你的问题,请参考以下文章