I have a PHP while loop that pulls from an SQL database and displays the contents in a table with two columns.
// Check Connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Select Data Table
$result = mysqli_query($con,"SELECT * FROM Recommendations") or die(mysqli_error);
// Split Data
$mid = ceil(mysqli_num_rows($result)/2);
// Display Content
while ($rows = mysqli_fetch_array($result)) {
$Name = $rows['Name'];
$Author = $rows['Author'];
$Cover = $rows['Link to Cover'];
$Link = $rows['Link to Profile'];
echo "<table><tr><td>
<a href='" . $Link . "' >$Name</a>
<br />
$Author
<br />
<a href='" . $Link . "' ><img src='" . $Cover . "' /></a>
</td>
<td>
<a href='" . $Link . "' >$Name</a>
<br />
$Author
<br />
<a href='" . $Link . "' ><img src='" . $Cover . "' /></a>
</td></tr></table>";
}
?>
I want to be able to display the looped results side by side in columns of two.
Example:
1 2
3 4 5 6
I've tried using pseudo classes to display only the even and odd results in the different table columns, but honestly have no idea how to do this. I'm new to PHP, so my apologies if the results are really obvious. Thanks in advance!