Re: database result: tables with 2 coloumns
| From: | Brad Bonkoski | Date: | Thu, 05 Sep 2002 23:39:16 +0000 |
| Subject: | Re: database result: tables with 2 coloumns | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-21592@lists.php.net to get a copy of this message | ||
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@hotmail.com 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