0

我想知道将数据行显示到 4x4 网格/表中的最简单方法是什么。我已经环顾了很长一段时间,但似乎找不到解决方案/不知道该怎么做。

这是我用来从 SQL 数据库中提取数据的代码。

<?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";
}
?>
4

2 回答 2

0

像这样的东西会起作用:

<?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
?>
于 2012-05-14T13:45:57.800 回答
0

我会这样做:

<?php
error_reporting(E_ALL);

require('json.php');

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` = '%s'", 'SET08101');

echo "<table>";

$result = mysql_query($sql) or die(mysql_error());

while ($row = mysql_fetch_array($result)){
   echo "<tr>
             <td>{$row['id']}</td>
             <td>{$row['module']}</td>
             <td>{$row['day']}</td>
             <td>{$row['start']}</td>
         </tr>";
}
echo "</table>";
?>
于 2012-05-14T13:57:26.000 回答