我想知道将数据行显示到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";
}
?>
答案 0 :(得分: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
?>
答案 1 :(得分: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>";
?>