在表中打印查询结果 [英] Printing Query Results in a Table

查看:57
本文介绍了在表中打印查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个如下所述的名为"info"的MySQL表,并且想按如下所述打印出一个HTML表,该怎么办?

If I had a MySQL table called "info" as described below and I wanted to print out an HTML table as described below, how would I do it?

MySQL表中的字段:

Fields in MySQL table:

id subject category actions date status

HTML表结构:两列,第一列包含字段"subject",第二列包含字段"actions",按"actions"降序排列.仅显示类别"与用户作为变量"$ find"输入的内容匹配的条目

HTML table structure: Two columns, first containing the field "subject", next containing the field "actions," sorted by "actions" descending. Only showing entries where "category" matches what the user entered as the variable "$find"

这是我要开始的地方,但我不确定下一步要去哪里:

Here is where I would start, but I'm not sure where to go next:

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

预先感谢

约翰

推荐答案

像这样:

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

这篇关于在表中打印查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆