> I have a few pages on my website which need to be divided up into
> columns and rows based on a category in a table. for example, on a links
> page, I have three different columns, one for bands, one for sites, and
> for other things. I'm storing those things in the table with a category
> field, so that when I output the data, it goes to the right place. However
> I'm a little unsure of the actual code to do this...

Assuming it's not critical to line up, say, the third band with the third
site in your table, right?

So all you really need is three columns with line breaks <BR> between
individual bands/sites/things:

    # Let the database sort out all our data for us, which is what databases
are good at:
    $query = "select id, category, name from stuff GROUP BY category order
by name";
    $stuff = mysql_query($query) or die(mysql_error());

    # We'll be tracking which category we are "on" with this variable:
    $last_category = '';

    # Go through all the data:
    while (list($id, $category, $name) = mysql_fetch_row($stuff)){
        if ($category != $last_category){
            # End previous column, if there was one ($last_category):
            if ($last_category){
                echo "</TD>\n";
            # Start a new column for the new category:
            echo "<TD><B>$category</B><BR>\n";

            # Remember which category we are on now:
            $last_category = $category;

        # Spew out an individual item:
        echo "<A HREF=http://details.php?id=$id>$name</A><BR>\n";
    # Finish off that final column:
    echo "</TD>\n";

WARNING [EMAIL PROTECTED] address is an endangered species -- Use
Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm

PHP General 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