I’m currently working on a web site database. The entire site is coded in PHP (procedural style and not object oriented), of course with the obligatory CSS/HTML, etc.
I have everything working properly, but I am having trouble figuring out how to format search results the way I’d like.
Right now, I am displaying my search results in table format, with each cell of the table displaying a different variable from the search. All these little tables display vertically in one column, one after the other, until the end of the results.
What I am trying to do is display two columns of search results, side by side, to fit more results on the screen at one time. I have been able to display two columns of duplicate results, but I’d like two columns of alternating, non-duplicate results.
The current layout of my results is something like:
Result 1
Result 2
Result 3
Result 4
What I have been able to accomplish in my attempts:
Result 1 Result 1
Result 2 Result 2
Result 3 Result 3
Result 4 Result 4
What I would like to have:
Result 1 Result 2
Result 3 Result 4
Result 5 Result 6
Result 7 Result 8
Can anyone shed some light on how to achieve this? I’m not sure if it's a simple CSS/HTML formatting solution, or a PHP/MySQL solution.
Below is the code that specifically relates to the loop that displays my results:
$link = mysqli_connect( ALL MY INFO );
include('strings.php'); //This script sets the SQL search string based on user input.
echo '<br />';
$query = mysqli_query($link, $string) or die ("Error retrieving search results. Error in (main.php) search function.");
$resultrows = mysqli_num_rows($query);
echo '<table>
<tr>
<td colspan=2>
<h3>Showing '.$resultrows.' results. </h3>
</td>
</tr>
<tr>
<td>';
while ($result = mysqli_fetch_assoc($query)){
include('results.php'); //This script formats each search result
}
echo ' </td>
<td>';
$query = mysqli_query($link, $string) or die ("Error retrieving search results. Error in (main.php) search function.");
while ($result = mysqli_fetch_assoc($query)){
include('results.php');
}
echo ' </td>
</tr>
</table>';