Page 1 of 1

PHP dispaying data in table

Posted: Thu Jun 28, 2012 5:00 am
by aduss
Another maybe easy question but I would like to display data from mysql database (like whole table) and I would like to display it in real table, when I do it now every single data are display in same row. I would like to do the list of members+ rank. I wrote it weird but I don't know how to explain it better. If anyone understands what I am talking about can you help me? Thanks :roll: ;)

Re: PHP dispaying data in table

Posted: Thu Jun 28, 2012 7:37 am
by Chris
By "real" table I take it you mean a HTML table:

First, start your table with the HTML tag, fill it with the results, then close the table tag:

Code: Select all

<table>
    <tr>
        <th>Username</th>
        <th>Rank</th>
    </tr>
    <?php
    // Your query
    $query = mysql_query("SELECT * FROM `users`");

    // loop through the results
    // $row = array of the row
    while( $row = mysql_fetch_assoc($query) )
    {
        echo '<tr>'; // new HTML table row

        echo '<td>' . $row['username'] . '</td>'; // column with username
        echo '<td>' . $row['rank'] . '</td>'; // column with rank

        echo '</tr>'; // close the HTML table row
    }
    ?>
</table>

Re: PHP dispaying data in table

Posted: Sun Jul 01, 2012 7:49 am
by aduss
Thanks :) ;)