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
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;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.