I have a database loaded with different churches information, I am trying to insert all the information from the database into a PHP table with 3 rows.
I would like the structure of each cell to be:
Church Name
Image
Pastor Name
I can easily insert all data into a table, but I cannot get it to display as 3 rows.
echo("<table>");
while($row = mysql_fetch_array($rs))
{
echo("<tr>");
echo("<td>");
echo("<a href='" . $row['website'] . "'>" . $row['churchName'] . "</a><br>");
echo("<img src=\"" . $row['image'] . "\"><br>");
echo($row['pastorName'] . "<br><br>");
echo("</td>");
echo("<td>");
echo("<a href='" . $row['website'] . "'>" . $row['churchName'] . "</a><br>");
echo("<img src=\"" . $row['image'] . "\"><br>");
echo($row['pastorName'] . "<br><br>");
echo("</td>");echo("<td>");
echo("<a href='" . $row['website'] . "'>" . $row['churchName'] . "</a><br>");
echo("<img src=\"" . $row['image'] . "\"><br>");
echo($row['pastorName'] . "<br><br>");
echo("</td>");
echo("</tr>");
}
echo("</table>");
Doing this causes me to have 3 rows in correct structure, but having duplicate data. I understand that I have not changed the id, but am not sure what I should do
You’re repeating the data on the row. If you want to show 3 items per row, you need to add a counter and a statement to draw the table row breaks, as below:
The last check ($int_Col > 1) should ensure the table is rendered properly with an empty cell – should span the correct amount of cells that were not drawn on the current row.