Search code examples
phpsqldatagridtabular

SQL Data into a Grid / Table


I was wondering what would be the easiest way to show rows of data into a 4x4 grid / table. I have looked around for quite awhile now and I can't seem to find a solution / understand how to do it.

Heres the code that I am using to extract the data from the SQL database.

<?php
require('json.php');
error_reporting(E_ALL);
mysql_connect("localhost", "root", "") or
die("Could not connect: " . mysql_error());
mysql_select_db("timetable") or die("No such database");
$sql = sprintf("
SELECT *
 FROM `event`
  WHERE `module` = 'SET08101'");

$result = mysql_query($sql)
 or die(mysql_error());
  while ($row = mysql_fetch_array($result)){
   print "<div>$row[id] $row[module] $row[day] $row[start]</div>\n";
}
?>

Solution

  • Something like this would work:

    <?php
    require('json.php');
    error_reporting(E_ALL);
    mysql_connect("localhost", "root", "") or
    die("Could not connect: " . mysql_error());
    mysql_select_db("timetable") or die("No such database");
    $sql = sprintf("
    SELECT *
     FROM `event`
      WHERE `module` = 'SET08101'");
    
    $result = mysql_query($sql)
     or die(mysql_error());
     ?>
     <table>
     <?php
      while ($row = mysql_fetch_array($result)){
       ?>
       <tr>
          <td><?php echo $row["id"];?></td>
          <td><?php echo $row["module"];?></td>
          <td><?php echo $row["day"];?></td>
          <td><?php echo $row["start"];?></td>
       </tr>
       <?php
      }
     ?>
     </table>
     <?php
    ?>