iamjonesy
iamjonesy

Reputation: 25122

Filling out a table horizontal and vertically with php and mysql

I'm fairly new to PHP so am not sure how to do this.

I have records in a database that link to images (profile pictures) that I want to display 5 along and 4 down. How would I do this?

Upvotes: 0

Views: 2162

Answers (1)

Josh K
Josh K

Reputation: 28883

First I would find a decent MySQL Tutorial. Then I would practice running some basic SELECT queries.

After you've done that it's as simple as

$sql = "SELECT `picture_link` FROM `users` WHERE 1";
$query = $this->db->query($sql);

foreach($query->result() as $row)
{
    echo $row->picture_link;
}

Note, this code is generalized

General table code

echo "<table><tr>";
$count = 1;
foreach($query->result() as $row)
{
    if($count % 5 == 0)
    {
        echo "</tr><tr>";
    }

    echo "<td>" . $row->picture_link . "</td>";
    $count++;
}

Upvotes: 1

Related Questions