2010-01-04 107 views
1

如果我有一个名为“info”的MySQL表,如下所述,并且我想打印出如下所述的HTML表格,那我该怎么做?在表中打印查询结果

字段在MySQL表:

id subject category actions date status 

HTML表结构:两列,含第一现场“主题”,下一个包含场“行动”,由“动作”降序排序。只显示条目,其中“类别”匹配什么用户输入的变量“$找到”

这里是我将开始,但我不知道在哪里去旁边:

$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)){ 

谢谢事先,

约翰

+2

我很抱歉,但是这气味像功课。 – 2010-01-04 14:27:34

+0

你知道如何用html制作表格吗? – user242294 2010-01-04 14:29:41

+0

Es ist nicht Hausaufgaben – John 2010-01-04 15:11:41

回答

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; ?> 
+0

谢谢... $ tab从哪里来?应该是$找到呢? – John 2010-01-04 15:01:08

+0

我认为$ tab应该是$ row – John 2010-01-04 15:10:58

+0

@John,yea,固定那个 – 2010-01-04 16:25:11