Return to Snippet

Revision: 9726
at November 19, 2008 01:26 by assaado


Updated Code
<?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
  }
?>

Revision: 9725
at November 19, 2008 01:26 by assaado


Updated Code
<?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>

Revision: 9724
at November 19, 2008 01:24 by assaado


Initial Code
<?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>

Initial URL

                                

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

Initial Title
Sorting MySQL data in a GRID

Initial Tags
mysql, php, html

Initial Language
PHP