PHP dispaying data in table

C++, C#, Java, PHP, ect...
Post Reply
aduss
Posts: 12
Joined: Sat Mar 17, 2012 6:02 pm

PHP dispaying data in table

Post 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: ;)
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: PHP dispaying data in table

Post 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>
Fighting for peace is declaring war on war. If you want peace be peaceful.
aduss
Posts: 12
Joined: Sat Mar 17, 2012 6:02 pm

Re: PHP dispaying data in table

Post by aduss »

Thanks :) ;)
Post Reply

Return to “Coding”