tags:

views:

32

answers:

2

Hello,

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

Thanks in advance,

John

A: 

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; ?>
Tatu Ulmanen
thanks... where does the $tab come from? should that be $find instead?
John
I think $tab should be $row
John
@John, yea, fixed that
Tatu Ulmanen
A: 

Here is a nice tutorial about Tables in HTML: http://www.w3schools.com/html/html_tables.asp