Justtechjobs.com Find a programming school near you






Online Campus Both


php-db | 2002091

Re: [PHP-DB] database result: tables with 2 coloumns From: Brad Bonkoski (bbonkosk <email protected>)
Date: 09/05/02

How's this? (MYSQL example)

$query = "select NAME from table_name";
$result = mysql_query($query)
or die("Invalid Query: $query");

$num_rows = mysql_num_rows($result);
$counter=1;
echo "<table border=1><tr>"; //start of table
for ($i=0;$i<$num_rows; $i++) //loop through the number of records
{
        $row = mysql_fetch_array($result); //Get associate row
        echo "<td>$row[0]</td>"; //Print out the NAME
        if ($counter == 2)
        {
                echo "</tr><tr>"; //Make a new Table row
                $counter=1; //Reset Counter
        }
        else
        {
                $counter++; //Just increment the counter
        }
}
echo "</tr></table>";
mysql_free_result($result);

HTH

-Brad

rainydays_sunshine <email protected> wrote:
> Hi..
>
> I'm creating a database result in a table, but I need to put it into 2
> columns of looping row like this:
>
> |name1 |name2 |
> |name3 |name4 |
> |name5 |name6 |
> |name7 |name8 |
> |name9 |name10 |
> etc...
>
> can anyone help me please...
>
> iman
>
>
>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php