I am trying to generate an HTML table from a MySQL query. Here is the format of the table I am trying to generate from a MySQL query:
--------------------------
| Image1 | Image2 | Image3 |
|----------------- --------|
| Name1 | Name2 | Name3 |
|----------------- --------|
| Image4 | Image5 | Image6 |
|----------------- --------|
| Name4 | Name5 | Name6 |
--------------------------
I am trying to create above table with my php code. The following is my code but it is not working properly can u help me out.
include_once("abc.php");
$query=mysql_query("select * from movix LIMIT 6");
echo'<table>';
$i=0;
while($sam=mysql_fetch_array($query))
{
$image = $sam['image'];
$name = $sam['name'];
if($i==0)
{
echo '<tr>';
}
echo '<td>'.' <img src="'.$image.'"/> '.'</td>';
echo '</tr>'; echo '<tr>';
echo '<td>'.$name.'</td>';
echo '<tr>';
if($i==2)
$i=-1;
}
$i++;
}
echo '</table>';
Can you please help me to understand what I am doing wrong with code and point me in the right direction? or please correct my code according to my above table.