【发布时间】:2017-06-18 17:06:21
【问题描述】:
我正在开发一个包含一些音频课程的网站,每门课程可以有多个课程。我想在自己的表格中显示每门课程以及不同的课程。
这是我的 SQL 语句:
表格:课程
id,标题
表格:课程
id、cid(课程id)、标题、日期、文件
$sql = "SELECT lessons.*, courses.title AS course FROM lessons INNER JOIN courses ON courses.id = lessons.cid GROUP BY lessons.id ORDER BY lessons.id" ;
有人可以帮我编写 PHP 代码吗?
这是我写的代码:
mysql_select_db($database_config, $config);
mysql_query("set names utf8");
$sql = "SELECT lessons.*, courses.title AS course FROM lessons INNER JOIN courses ON courses.id = lessons.cid GROUP BY lessons.id ORDER BY lessons.id" ;
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
echo "<p><span class='heading1'>" . $row['course'] . "</span> </p> ";
echo "<p class='datum'>Posted onder <a href='*'>*</a>, latest update on " . strftime("%A %d %B %Y %H:%M", strtotime($row['date']));
}
echo "</p>";
echo "<class id='text'>";
echo "<p>...</p>";
echo "<table border: none cellpadding='1' cellspacing='1'>";
echo "<tr>";
echo "<th>Nr.</th>";
echo "<th width='450'>Lesso</th>";
echo "<th>Date</th>";
echo "<th>Download</th>";
echo "</tr>";
echo "<tr>";
echo "<td>" . $row['nr'] . "</td>";
echo "<td>" . $row['title'] . "</td>";
echo "<td>" . strftime("%d/%m/%Y", strtotime($row['date'])) . "</td>";
echo "<td><a href='audio/" . rawurlencode($row['file']) . "'>MP3</a></td>";
echo "</tr>";
echo "</table>";
echo "<br>";
}
?>
【问题讨论】:
-
请详细描述您遇到的问题
-
代码是否存在不符合预期的问题?我们在这里并没有真正进行开放式代码审查。但我确实有一个建议是将代码与标记分开。使用
echo输出HTML 代码的格式一般很差。 -
你为什么在做
$row = mysql_fetch_array($result),紧接着是$row = mysql_fetch_assoc($result)的循环?
标签: php mysql database html-table