views:

36

answers:

2

// Database Settings define('DB_HOST', '**'); define('DB_PORT', '**'); define('DB_USER', '**'); define('DB_PASS', '**'); define('DB_NAME', '**');

// Connection to Database $database = new MySQLi(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT);

$sql = 'SELECT AManufactureBrand.brand, AManufactureModel.model, AManufactureEdition.edition' . ' FROM AManufactureModel' . ' INNER JOIN AManufactureBrand ON AManufactureModel.brand_id = AManufactureBrand.brand_id' . ' INNER JOIN AManufactureEdition ON AManufactureModel.model_id = AManufactureEdition.model_id' . ' WHERE AManufactureEdition.edition=\'345i\'';

$resultSet = $database->query($sql);

// Begin building some HTML output

$html = ' Editions ';

while ($row = $resultSet->fetch_assoc()) { $html .= '' . $row['brand'] . ''; $html .= '' . $row['model'] . ''; $html .= '' . $row['edition'] . ''; }

$html .= '';

echo $html; ?>

For example this query calls up BMW 3Series 345i, I have two results from mysql printed to a table on my website. The problem the two records print out on one column going down onwards.

Currently I get a result like this on my webpage two mysql records printing vertical down one column.

http://farm5.static.flickr.com/4089/5037004046_bfa10ffc7b.jpg

I'm trying to make it go across like this and print multiple cars next to each-other horizontally across.

http://farm5.static.flickr.com/4154/5036385491_fac72b5016.jpg
+1  A: 

I know there's gotta be a better way to do it with HTML but this should work:

$ths = $tds1 = $tds2 = $tds3 = '';

while ($row = $resultSet->fetch_assoc())
{
$ths .= '<td>Editions</td>';
$tds1 .= '<td>' . $row['brand'] . '</td>';
$tds2 .= '<td>' . $row['model'] . '</td>';
$tds3 .= '<td>' . $row['edition'] . '</td>';
}

$html = "<table border="0">
<tr>$ths</tr>
<tr>$tds1</tr>
<tr>$tds2</tr>
<tr>$tds3</tr>
</table>
";

You could also just have multiple tables in succession.

methodin
+2  A: 

Not sure exactly what you're trying to do, but I would suggest replacing this:

// Begin building some HTML output

$html = '<table border="0">
<tr>
<th>Editions</th>
</tr>';

while ($row = $resultSet->fetch_assoc())
{
$html .= '<tr><td>' . $row['brand'] . '</td></tr>';
$html .= '<tr><td>' . $row['model'] . '</td></tr>';
$html .= '<tr><td>' . $row['edition'] . '</td></tr>';
}

$html .= '</table>';

with this:

// Begin building some HTML output

$html = '<table border="0">
<tr>
<th>Brand</th>
<th>Model</th>
<th>Edition</th>
</tr>\n';

while ($row = $resultSet->fetch_assoc())
{
$html .= '<tr>';
$html .= '<td>' . htmlentities($row['brand']) . '</td>';
$html .= '<td>' . htmlentities($row['model']) . '</td>';
$html .= '<td>' . htmlentities($row['edition']) . '</td>';
$html .= '</tr>\n';
}

$html .= '</table>';

That will give you proper 3 column output. If that's not what you wanted, then clarify your question.

dkamins
I clarified my question above thanks for your input so far.
bradpotts
Still not clear what you're trying to do... Sorry. Hopefully you can work something out from this answer.
dkamins