Hi all

I apologies again in advance for the seemingly stupid question. I have tried googling this once but can't see to get the answer i'm looking for.

Basically i have a form which can query the database depending upon what the user has selected. The trouble is if multiple results come up when it comes to building the table for the output, it seems to link it all together in one big table without putting a break in between results.

I suspect that the problem lies with the WHILE statement not being setup correctly for this particular type of setup, however i'm not 100% sure which type of statement i should be using instead.

Current snipit of the code:

if ($search_enhance == 0) {
    // Search query without LIKE flag
    $result = mysql_query("SELECT * FROM db_routers WHERE " . $search_type . "='" . $search_string . "' ORDER BY ID ASC");
else {
    // Search query with LIKE flag
    $result = mysql_query("SELECT * FROM db_routers WHERE " . $search_type . " LIKE '%" . $search_string . "%' ORDER BY ID ASC");

// Get the results from the database
while($row = mysql_fetch_array($result)) {

echo "<tr>";
    echo "<td><b>ID</b></td>";
    echo "<td>" . $row['ID'] . "</td>";
echo "</tr>";
echo "<tr>";
    echo "<td><b>Dispatch Time</b></td>";
    echo "<td>" . $row['dispatchtime'] . "</td>";
echo "</tr>";
echo "<tr>";
    echo "<td><b>Company Name</b></td>";
    echo "<td>" . $row['company'] . "</td>";
echo "</tr>";
echo "<tr>";
    echo "<td><b>Dispatched By</b></td>";
    echo "<td>" . $row['dispatchedby'] . "</td>";
echo "</tr>";
echo "<p>";

5 Years
Discussion Span
Last Post by sleign

You want a separate row for each record?

echo "<table><thead><tr><th>ID</th><th>Dispatch Time</th><th>Company Name</th><th>Dispatched By</th></tr></thead><tbody>";

  echo "<tr><td>{$row['ID']}</td><td>{$row['dispatchtime']}</td><td>{$row['company']}</td><td>{$row['dispatchedby']}</td></tr>";
echo "</tbody></table>";

Edited by diafol: shaj


I think ardav pretty much sums it up except that I noticed in your code you aren't using the table delcaration at all:


You were doing a paragraph within a paragraph within a paragraph, etc for however many results you had -- starting after the first iteration of your while loop. The way ardav did it is pretty much the cut and dry way of doing it, however, if you were looking to add more whitespace between each row - or select rows - you could just add padding to each "td" in the row you want more whitespace in, which will give you more space.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.