>""Matt Nigh"" <[EMAIL PROTECTED]> wrote in message
>014501c0fe67$945a3400$[EMAIL PROTECTED]">news:014501c0fe67$945a3400$[EMAIL PROTECTED]...
>hello knowledgeable people of the php-db list,

;-) flattery will get you everywhere ;-)

>I need a section of a record label site with a releases section listed
>horizontally but here's the twist: after every 4 releases, I want the
releases to >move to the next columns below.
>release#1, release#2, release#3, release#4
>release#5, release#6
>each release is stored in a database called almavale_releases and there are
6 >rows:
>id, bandname, albumtitle, coverpic, albumcode, datereleased

Ig... first thing, be precise.  Your *table* has six *fields*.

What do you want 'release#1' to look like?  Something like 'albumtitle

>so what i need to know is what php code do I need to accomplish this?

There's a bit of a trick to it; a table expects the same number of columns
in each row.  Most browsers will handle errors anyway, but it's safest to
get it right.

For your example above, the resulting HTML should look like


Notice the two empty items in the second block!

Try this:
    // connect to database server
    mysql_connect("host", "user", "pwd");

    // fetch data
    $res = mysql_query("SELECT bandname, albumtitle FROM
    $num = mysql_num_rows($res);

    // calculate table dimensions
    $per_row = 4;
    $rows = (int) (($num + $per_row - 1) / $per_row);

    $count = 0;
    echo "\n<table>";
    for ($i = 0; $i < $rows; $i++) {
        echo "\n\t<tr>";
        for ($j = 0; $j < $per_row; $j++) {
            if ($count < $num) {
                $it = mysql_fetch_array($res);
                $album = $it["albumtitle"];
                $band = $it["bandname"];
                $item = "$album ($band)";
                $item = "";

            echo "\n\t\t<td>$item</td>";
        echo "\n\t</tr>";
    echo "</table>";

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to