如果我有一个名为“info”的MySQL表,如下所述,我想打印出如下所述的HTML表格,我该怎么做?
MySQL表中的字段:
id subject category actions date status
HTML表格结构:两列,首先包含字段“subject”,其次包含字段“actions”,按“actions”降序排序。仅显示“类别”与用户输入的变量“$ find”
相匹配的条目这是我要开始的地方,但我不知道下一步该去哪里:
$result=mysql_query("SELECT subject, actions FROM info WHERE category='$find' ORDER BY votes DESC")
or die(mysql_error());
if(mysql_num_rows($result)>0){
while($table=mysql_fetch_row($result)){
提前致谢,
约翰
答案 0 :(得分:0)
像这样:
<?php
$result = mysql_query("SELECT subject, actions FROM info WHERE category='$find' ORDER BY votes DESC") or die(mysql_error());
if(mysql_num_rows($result) > 0): ?>
<table>
<tr>
<th>Subject</th>
<th>Actions</th>
<tr>
<?php while($row = mysql_fetch_assoc($result)): ?>
<tr>
<td><?php echo $row['subject']; ?></td>
<td><?php echo $row['actions']; ?></td>
</tr>
<?php endwhile; ?>
</table>
<?php endif; ?>