开发者

Printing Query Results in a Table

开发者 https://www.devze.com 2022-12-15 04:50 出处:网络
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?

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?

Fields in MySQL table:

id subject category actions date status

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 enter开发者_JAVA百科ed 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)){

Thanks in advance,

John


Like this:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号