Jump to content

PHP/MySQL - Result on same line


imdead

Recommended Posts

Hello, i created this script for a client and have ran into an annoying error with the results displaying on a new line for each result instead of side by side, any help is welcome :D

 

Cheers

 

					  <?php
				  $subcat = mysql_real_escape_string(strip_tags(htmlspecialchars(protect($_GET['subcat']))));
				  $cat =  mysql_real_escape_string(strip_tags(htmlspecialchars(protect($_GET['cat']))));
$sql = @mysql_query("SELECT * FROM cakes WHERE category =\"$cat\" AND sub_cat=\"$subcat\" ORDER BY id DESC");
while ($row = mysql_fetch_array($sql)) {
$reference = $row['reference'];
$image = $row['image'];
echo ("<p><img src='./images/cakes/$image' height='289px' width='177px' alt='IMAGE OF CAKE'></img><br />");
echo ("<b>Reference:</b>$reference"."</p>");
}
if (!$reference) {
echo 'There are no cakes in this category yet.';
}
?>

 

I know the errors only going to be something small i'm missing, but i've been coding all day :P

post-60781-13482403165149_thumb.png

Link to comment
https://forums.phpfreaks.com/topic/255032-phpmysql-result-on-same-line/
Share on other sites

ever think of using a table?

$html = '<table><tr>';
$cols = 3;// can be any size you want
$x = 0;
while ($row = mysql_fetch_array($sql)) 
{
$x++;
$reference = $row['reference'];
$image = $row['image'];
$html .= '<td>';
$html .= '<p><img src="./images/cakes/'.$image.'" height="289px" width="177px" alt="IMAGE OF CAKE"></img><br />';
$html .= '<b>Reference:</b>'.$reference.'.</p>';
$html .= '</td>';
if ($x == $cols)
{
	$html .= '</tr><tr>';
	$x=0;
}
}

if (!$reference) 
{
$html .= '<td>There are no cakes in this category yet.</td>';
}
echo $html;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.