jbrill Posted June 28, 2007 Share Posted June 28, 2007 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: ". $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 https://forums.phpfreaks.com/topic/57622-simple-if-statement-question/ Share on other sites More sharing options...
per1os Posted June 28, 2007 Share Posted June 28, 2007 <?php //..... $num = mysql_num_rows($featuredproducts); $center = ($num == 1)?"center":"left"; echo"<td align=\"" . $center . "\" height=\"260\">"; Link to comment https://forums.phpfreaks.com/topic/57622-simple-if-statement-question/#findComment-285244 Share on other sites More sharing options...
jbrill Posted June 28, 2007 Author Share Posted June 28, 2007 confused...sorry im new Link to comment https://forums.phpfreaks.com/topic/57622-simple-if-statement-question/#findComment-285261 Share on other sites More sharing options...
per1os Posted June 28, 2007 Share Posted June 28, 2007 <?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 https://forums.phpfreaks.com/topic/57622-simple-if-statement-question/#findComment-285262 Share on other sites More sharing options...
jbrill Posted June 28, 2007 Author Share Posted June 28, 2007 gettiign an error to do with this line: $center = ($num == 1)?"center"; it is saying Parse error: parse error in /home/httpd/vhosts/my url/httpdocs/suburl/detailed_products.php on line 79 Link to comment https://forums.phpfreaks.com/topic/57622-simple-if-statement-question/#findComment-285303 Share on other sites More sharing options...
teng84 Posted June 28, 2007 Share Posted June 28, 2007 $center = ($num == 1)?"center":"put somethinghere"; that is same as if ($num == 1) { "center" } else { "put somethinghere" } hope that helps Link to comment https://forums.phpfreaks.com/topic/57622-simple-if-statement-question/#findComment-285311 Share on other sites More sharing options...
jbrill Posted June 28, 2007 Author Share Posted June 28, 2007 getting a parse error on this line now... echo"<table border=\"0\" class=\"" . $center . "\">"; Link to comment https://forums.phpfreaks.com/topic/57622-simple-if-statement-question/#findComment-285319 Share on other sites More sharing options...
pocobueno1388 Posted June 28, 2007 Share Posted June 28, 2007 Change it to this: echo "<table border='0' class='$center'>"; Link to comment https://forums.phpfreaks.com/topic/57622-simple-if-statement-question/#findComment-285323 Share on other sites More sharing options...
jbrill Posted June 28, 2007 Author Share Posted June 28, 2007 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 https://forums.phpfreaks.com/topic/57622-simple-if-statement-question/#findComment-285326 Share on other sites More sharing options...
teng84 Posted June 28, 2007 Share Posted June 28, 2007 show the code after that line because i think thats ok Link to comment https://forums.phpfreaks.com/topic/57622-simple-if-statement-question/#findComment-285328 Share on other sites More sharing options...
teng84 Posted June 28, 2007 Share Posted June 28, 2007 show the code after that line because i think thats ok oops sorry before that line Link to comment https://forums.phpfreaks.com/topic/57622-simple-if-statement-question/#findComment-285330 Share on other sites More sharing options...
jbrill Posted June 28, 2007 Author Share Posted June 28, 2007 echo"<tr>"; echo"<td width=\"340\" align=\"center\"><span class=\"listingtext\"><strong>". $row['name'] ."</strong></span></td>"; echo"</tr>"; Link to comment https://forums.phpfreaks.com/topic/57622-simple-if-statement-question/#findComment-285331 Share on other sites More sharing options...
pocobueno1388 Posted June 28, 2007 Share Posted June 28, 2007 Theres nothing wrong with that either. Post your entire updated code. Link to comment https://forums.phpfreaks.com/topic/57622-simple-if-statement-question/#findComment-285333 Share on other sites More sharing options...
jbrill Posted June 28, 2007 Author Share Posted June 28, 2007 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: ". $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 https://forums.phpfreaks.com/topic/57622-simple-if-statement-question/#findComment-285348 Share on other sites More sharing options...
teng84 Posted June 28, 2007 Share Posted June 28, 2007 wheres that line any way sometimes parse error means that you forgot the ; terminator if you dont have that line maybe the error is within the braces Link to comment https://forums.phpfreaks.com/topic/57622-simple-if-statement-question/#findComment-285353 Share on other sites More sharing options...
jbrill Posted June 28, 2007 Author Share Posted June 28, 2007 the image code is perfect, its the exact same code that was working before... Link to comment https://forums.phpfreaks.com/topic/57622-simple-if-statement-question/#findComment-285354 Share on other sites More sharing options...
pocobueno1388 Posted June 28, 2007 Share Posted June 28, 2007 That couldn't be the entire code, because it doesn't contain any parse errors...plus it doesn't have 85 lines. Post your ENTIRE code...or the code that goes along with the error. Link to comment https://forums.phpfreaks.com/topic/57622-simple-if-statement-question/#findComment-285355 Share on other sites More sharing options...
jbrill Posted June 28, 2007 Author Share Posted June 28, 2007 <? 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: ". $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>"; } ?> </td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/57622-simple-if-statement-question/#findComment-285358 Share on other sites More sharing options...
pocobueno1388 Posted June 28, 2007 Share Posted June 28, 2007 I'm still not getting a parse error... Link to comment https://forums.phpfreaks.com/topic/57622-simple-if-statement-question/#findComment-285361 Share on other sites More sharing options...
teng84 Posted June 28, 2007 Share Posted June 28, 2007 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 https://forums.phpfreaks.com/topic/57622-simple-if-statement-question/#findComment-285365 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.