Hey guys. I'm still learning PHP and have run into a formatting problem that I thought would be simple but am finding myself running around in circles trying to solve.
I'm calling a mySQL database with PHP and displaying the information in a table. I would like it to display the information so that each of the database row information is grouped together and displayed in columns side-by-side. Instead, all the information is listing horizontally and stacked on top of each other just as it appears in the database. So, right now it's displaying like this:
a info info info info
b info info info info
c info info info info
Does anyone know how to format the table so that it displays like this:
a | b | c
info info info
info info info
d | e | f
info info info
info info info
Here is the code I'm using:
I'm calling a mySQL database with PHP and displaying the information in a table. I would like it to display the information so that each of the database row information is grouped together and displayed in columns side-by-side. Instead, all the information is listing horizontally and stacked on top of each other just as it appears in the database. So, right now it's displaying like this:
a info info info info
b info info info info
c info info info info
Does anyone know how to format the table so that it displays like this:
a | b | c
info info info
info info info
d | e | f
info info info
info info info
Here is the code I'm using:
Code:
<?php
$db_host = 'localhost';
$db_user = 'user_name';
$db_pwd = 'password';
$database = 'database_name';
if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");
if (!mysql_select_db($database))
die("Can't select database");
$query="SELECT * FROM products WHERE advertisercategory='briefs'";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
?>
<?
$i=0;
while ($i < $num) {
$image=mysql_result($result,$i,"imageurl");
$namet=mysql_result($result,$i,"name");
$sku=mysql_result($result,$i,"sku");
$price=mysql_result($result,$i,"price");
$category=mysql_result($result,$i,"advertisercategory");
$updated=mysql_result($result,$i,"lastupdated");
$affiliate=mysql_result($result,$i,"buyurl");
?>
<table>
<tr>
<td><a href="<? echo $affiliate; ?>"><img width="110" src="<? echo $image; ?>"></a></font></td>
<td><? echo $first." ".$last; ?></font></td>
<td><? echo $fax; ?></font></td>
<td><? echo $email; ?></font></td>
<td><a href="<? echo $affiliate; ?>">Buy Now</a></font></td>
<td><? echo $web; ?></font></td>
</tr>
<?
$i++;
}
echo "</table>";
?>