I need to display pictures from MySQL like this:
-------|-------|-------|-------|
Pic 1 | Pic 2 | Pic 3 | Pic 4 |
-------|-------|-------|-------| ----> there can be more then 4 this way>
Pic 5 | Pic 7 | Pic 8 | Pic 9 |
-------|-------|-------|-------|
There can not be more then two rows but there can be unlimited amount of columns to the right.
I think i need to use a foreach loop. Does some one have a code that will do this?
My code so far:
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT title FROM donuts");
while ($row = mysqli_fetch_assoc($result)) {
for ($x=0; $x<=2; $x++)
{
if($x==0)
{
echo "<tr>";
}
else
{
echo "<td>".$row['title']."</td>";
$x++;
if($x==1) {
echo "</tr>";
}
}
}
}
What i get
-------|
pic 1 |
-------|
-------|
pic 2 |
-------|
-------|
pic 3 |
-------|
-------|
pic 4 |
-------|
-------|
pic 5 |
-------|
-------|
pic 6 |
-------|