help with array in columns

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wardy
Forum Newbie
Posts: 2
Joined: Wed Sep 10, 2003 3:03 pm

help with array in columns

Post by wardy »

I am new to php

Can anybody please help cant get an array to go across columns only to run down one after the other

here is the code
<?

include('config.php');

//Open Connection to database
$db = mysql_connect("$hostname", "$username","$password");
mysql_select_db("$database",$db);

?>



<?

$result = mysql_query("SELECT * FROM models", $db);

while ($product=mysql_fetch_array($result))
{
?>
<table width="90%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td><?=$product[name]?></td>
<td><?=$product[age]?></td>

</tr>
</table>

<?
}
?>

here is the result

http://www.dave-ward.co.uk/model/model.php
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

Code: Select all

<?php
echo '<table width="90%" border="1" cellspacing="0" cellpadding="0">'; 
echo '<tr> ';
$c = 1;
while ($product=mysql_fetch_array($result)) 
{ 
 
if($c == 2)
{
    echo '</tr><tr>';
}
echo '<td>'.$product[name].'</td> ';
$c++;
}
</tr> 
</table> 
 



?>
I haven't tested it but you get the idea I hope
Post Reply