Jump to content

simple "if" statement question


jbrill

Recommended Posts

Hey just have a quick question, I am displaying products in a table 2 across with the code below, however, if there is only one product i would like it to be centered not aligned to the left. i need help with an "if" statement that will allow me to be able to do this.

 

here is the code i have now. keep in mind, the products are displayed inline and rows of 2 by using a css class so i will make a new class that represent if only one product shows up.

<?
	 $featuredresults = mysql_query("SELECT * FROM products WHERE cat='".$_GET['cat']."' AND publish=1 AND featured=1");
              
              while($row = mysql_fetch_array($featuredresults))
	{



echo"<table border=\"0\" class=\"featuredproduct\">";
echo"<tr>";
echo"<td><img src=\"images\featured.gif\"></td>";
echo"</tr>";
echo"<tr>";
echo"<td align=\"center\" height=\"260\">";
if($row['photo']==null || !file_exists($row['photo'])) {
						echo "<img src=\"images/nophoto.gif\" width=66 height=39 border=0>";
					} else {
						// if image exists, resize and display

						$size = getimagesize($row['photo']);
						$width = $size[0];
						$height = $size[1];

						$max = 250;

						if($width > $max || $height > $max) {
							$ratio = $width/$height;

							if($width < $height) {
								// width is smaller than height, hence the height should be adjuste to max first. 
								$resize = $max/$height;
								$nheight = 250;
								$nwidth = ceil($width*$resize);
							}

							if($width > $height) {
								// height is smaller than width, hence the width should be adjuste to max first. 
								$resize = $max/$width;
								$nwidth = 250;
								$nheight = ceil($height*$resize);
							}

						} else {
							$nwidth=$width;
							$nheight=$height;
						}

						echo "<img src=\"".$row['photo']."\" border=0 width=\"".$nwidth."\" height=\"".$nheight."\">";
					}"</td>";
echo"</tr>";
echo"<tr>";
echo"<td width=\"340\" align=\"center\"><span class=\"listingtext\"><strong>". $row['name'] ."</strong></span></td>";
echo"</tr>";
echo"<tr>";
echo"<td width=\"340\" align=\"center\"><span class=\"listingtext\">Product Number&#58;  ". $row['prod_number'] . "</span></td>";
echo"</tr>";
echo"<tr>";
echo"<td width=\"340\" align=\"center\"><span class=\"price\">Price&#58;  ". $row['price'] . "</span></td>";
echo"</tr>";
echo"<tr>";
echo"<td width=\"340\" align=\"center\"><a class=\"details\" href=\"details.php?id=".$row['id']."&cat=".$row['cat']."&table=products\">Details</a></td>";
echo"</tr>";
echo"</table>";

}
?>	

 

 

Link to comment
Share on other sites

<?php
	 $featuredresults = mysql_query("SELECT * FROM products WHERE cat='".$_GET['cat']."' AND publish=1 AND featured=1");
              
              while($row = mysql_fetch_array($featuredresults))
	{



echo"<table border=\"0\" class=\"featuredproduct\">";
echo"<tr>";
echo"<td><img src=\"images\featured.gif\"></td>";
echo"</tr>";
echo"<tr>";
$num = mysql_num_rows($featuredresults);
$center = ($num == 1)?"center":"left";
echo"<td align=\"" . $center . "\" height=\"260\">";
if($row['photo']==null || !file_exists($row['photo'])) {
						echo "<img src=\"images/nophoto.gif\" width=66 height=39 border=0>";
					} else {
						// if image exists, resize and display

						$size = getimagesize($row['photo']);
						$width = $size[0];
						$height = $size[1];

						$max = 250;

						if($width > $max || $height > $max) {
							$ratio = $width/$height;

							if($width < $height) {
								// width is smaller than height, hence the height should be adjuste to max first. 
								$resize = $max/$height;
								$nheight = 250;
								$nwidth = ceil($width*$resize);
							}

							if($width > $height) {
								// height is smaller than width, hence the width should be adjuste to max first. 
								$resize = $max/$width;
								$nwidth = 250;
								$nheight = ceil($height*$resize);
							}

						} else {
							$nwidth=$width;
							$nheight=$height;
						}

						echo "<img src=\"".$row['photo']."\" border=0 width=\"".$nwidth."\" height=\"".$nheight."\">";
					}"</td>";
echo"</tr>";
echo"<tr>";
echo"<td width=\"340\" align=\"center\"><span class=\"listingtext\"><strong>". $row['name'] ."</strong></span></td>";
echo"</tr>";
echo"<tr>";
echo"<td width=\"340\" align=\"center\"><span class=\"listingtext\">Product Number:  ". $row['prod_number'] . "</span></td>";
echo"</tr>";
echo"<tr>";
echo"<td width=\"340\" align=\"center\"><span class=\"price\">Price:  ". $row['price'] . "</span></td>";
echo"</tr>";
echo"<tr>";
echo"<td width=\"340\" align=\"center\"><a class=\"details\" href=\"details.php?id=".$row['id']."&cat=".$row['cat']."&table=products\">Details</a></td>";
echo"</tr>";
echo"</table>";

}
?>	

Link to comment
Share on other sites

k that fixed that problem.. now theres a problem here:

 

 

if($row['photo']==null || !file_exists($row['photo'])) {

 

 

Parse error: parse error in /home/httpd/vhosts/bbold.com/httpdocs/haney/detailed_products.php on line 85

 

Link to comment
Share on other sites

heres the entire code, the most recent error is a parse error on 122


<?
	 $featuredresults = mysql_query("SELECT * FROM products WHERE cat='".$_GET['cat']."' AND publish=1 AND featured=1");
              
              while($row = mysql_fetch_array($featuredresults))
	{




$num = mysql_num_rows($featuredresults);
$center = ($num == 1)?"featuredproduct":"productdisplay";
echo"<table border='0' class='$center'>";
echo"<tr>";
echo"<td><img src=\"images\featured.gif\"></td>";
echo"</tr>";
echo"<tr>";

echo"<td height=\"260\">";
if($row['photo']==null || !file_exists($row['photo'])) {
						echo "<img src=\"images/nophoto.gif\" width=66 height=39 border=0>";
					} else {
						// if image exists, resize and display

						$size = getimagesize($row['photo']);
						$width = $size[0];
						$height = $size[1];

						$max = 250;

						if($width > $max || $height > $max) {
							$ratio = $width/$height;

							if($width < $height) {
								// width is smaller than height, hence the height should be adjuste to max first. 
								$resize = $max/$height;
								$nheight = 250;
								$nwidth = ceil($width*$resize);
							}

							if($width > $height) {
								// height is smaller than width, hence the width should be adjuste to max first. 
								$resize = $max/$width;
								$nwidth = 250;
								$nheight = ceil($height*$resize);
							}

						} else {
							$nwidth=$width;
							$nheight=$height;
						}

						echo "<a href=\"". $row['photo'] ."\" target=\"_blank\"><img src=\"".$row['photo']."\" border=0 width=\"".$nwidth."\" height=\"".$nheight."\"></a>";
					}"</td>";
echo"</tr>";
echo"<tr>";
echo"<td width=\"340\" align=\"center\"><span class=\"listingtext\"><strong>"
. $row['name'] ."</strong></span></td>";
echo"</tr>";
echo"<tr>";
echo"<td width=\"340\" align=\"center\"><span class=\"listingtext\">Product Number&#58;  ". $row['prod_number'] . "</span></td>";
echo"</tr>";
echo"<tr>";
echo"<td width=\"340\" align=\"center\"><span class=\"price\">Price&#58;  ". $row['price'] . "</span></td>";
echo"</tr>";
echo"<tr>";
echo"<td width=\"340\" align=\"center\"><a class=\"details\" href=\"details.php?id=".$row['id']."&cat=".$row['cat']."&table=products\">Details</a></td>";
echo"</tr>";
echo"</table>";

}
?>

 

 

Link to comment
Share on other sites

<? include 'includes/header.php' ?>
  <td width="722" valign="top">
<!---Display Subcategories--->
<table width="100%" border="0">
<tr>
<td width="400" valign="middle">
<span class="subcatTitle">Sub Categories:</span>
<?
$subcat = mysql_query("SELECT * FROM subcategory WHERE cat='".$_GET['cat']."' ORDER by subcat");
while($row = mysql_fetch_array($subcat))
	{
	echo"<span class=\"subcat\"><a class=\"subcat\" href=\"subcat_products.php?cat=".$row['cat']."&subcat=".$row['subc']."&table=products\">". $row['subcat'] ."</a> / </span>";
	}


?>
</td>
<td align="right" valign="bottom">
<?
$showcat = mysql_query("SELECT * FROM category WHERE cat='".$_GET['cat']."'");
while($row = mysql_fetch_array($showcat))
	{
	echo"<span class=\"titlelarge\">".$row['category']."</span>";
	}	
?><br>


<?


if(isset($cat)) {
$hopcat="cat=".$cat;
}

if(isset($p))
{
if(isset($subcat) || isset($cat)) {
	$hoppage="&p=".$p;
} else {
	$hoppage="p=".$p;
}
} else {
$hoppage="";
}

$hopsql=$hopcat.$hoppage;

echo "<img src=\"images/quicklist.gif\"> <a class=\"quicklisting\" href=\"quick_products.php?".$hopsql."\">Quick Listing</a>";

?>
</td>
</tr>
</table>
<img src="images/fade_to_white.gif">




</td>
  </tr>
<tr>
	<td width="722" height="5" valign="top" align="center">
<table width="100%" border="0">
<tr>
<td valign="top" align="center">
<?
	 $featuredresults = mysql_query("SELECT * FROM products WHERE cat='".$_GET['cat']."' AND publish=1 AND featured=1");
              
              while($row = mysql_fetch_array($featuredresults))
	{




$num = mysql_num_rows($featuredresults);
$center = ($num == 1)?"featuredproduct":"productdisplay";
echo"<table border='0' class='$center'>";
echo"<tr>";
echo"<td><img src=\"images\featured.gif\"></td>";
echo"</tr>";
echo"<tr>";

echo"<td height=\"260\">";
if($row['photo']==null || !file_exists($row['photo'])) {
						echo "<img src=\"images/nophoto.gif\" width=66 height=39 border=0>";
					} else {
						// if image exists, resize and display

						$size = getimagesize($row['photo']);
						$width = $size[0];
						$height = $size[1];

						$max = 250;

						if($width > $max || $height > $max) {
							$ratio = $width/$height;

							if($width < $height) {
								// width is smaller than height, hence the height should be adjuste to max first. 
								$resize = $max/$height;
								$nheight = 250;
								$nwidth = ceil($width*$resize);
							}

							if($width > $height) {
								// height is smaller than width, hence the width should be adjuste to max first. 
								$resize = $max/$width;
								$nwidth = 250;
								$nheight = ceil($height*$resize);
							}

						} else {
							$nwidth=$width;
							$nheight=$height;
						}

						echo "<a href=\"". $row['photo'] ."\" target=\"_blank\"><img src=\"".$row['photo']."\" border=0 width=\"".$nwidth."\" height=\"".$nheight."\"></a>";
					}"</td>";
echo"</tr>";
echo"<tr>";
echo"<td width=\"340\" align=\"center\"><span class=\"listingtext\"><strong>"
. $row['name'] ."</strong></span></td>";
echo"</tr>";
echo"<tr>";
echo"<td width=\"340\" align=\"center\"><span class=\"listingtext\">Product Number&#58;  ". $row['prod_number'] . "</span></td>";
echo"</tr>";
echo"<tr>";
echo"<td width=\"340\" align=\"center\"><span class=\"price\">Price&#58;  ". $row['price'] . "</span></td>";
echo"</tr>";
echo"<tr>";
echo"<td width=\"340\" align=\"center\"><a class=\"details\" href=\"details.php?id=".$row['id']."&cat=".$row['cat']."&table=products\">Details</a></td>";
echo"</tr>";
echo"</table>";

}
?>
</td>
  </tr>
</table>

Link to comment
Share on other sites

echo "<a href=\"". $row['photo'] ."\" target=\"_blank\"><img src=\"".$row['photo']."\" border=0 width=\"".$nwidth."\" height=\"".$nheight."\"></a>";

}"</td>";////////////////////////////

maybe thats the prob even i dont get the error from that you forgot to eco the td

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.