Page 1 of 1

help with array in columns

Posted: Wed Sep 10, 2003 3:11 pm
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

Posted: Wed Sep 10, 2003 5:23 pm
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