Page 1 of 1

Displaying Info In Tables

Posted: Sat Feb 28, 2004 3:38 pm
by John Cartwright
Okay This snipplet of code takes the latest 6 featured products and displays them in this fashion ( or should ).

PRODUCT 1 |||||||| SEPERATOR COLUMN |||||||||| PRODUCT 2
PRODUCT 3 |||||||| SEPERATOR COLUMN |||||||||| PRODUCT 4
PRODUCT 5 |||||||| SEPERATOR COLUMN |||||||||| PRODUCT 6

It is only showing like a little bit of the first product... obviously something is really wrong. What I'm having problems with is these kinds of things which open up a row, add a column and close up the tags....

Code: Select all

<?php
				if (($i % 1 == 1) || ($i % 1 == 3) || ($i % 1 == 5)){
				echo  "<tr>".
						 "<td width="49%">";
						 
				}elseif (($i % 1 == 2) || ($i % 1 == 4) || ($i % 1 == 6)){
				echo     "<td width="1%" bgcolor="#000000">".
						 "<td width="49%">";
				}
?>
This is one of them which opens up all the tags.. it checks to see if it is putting the first column in the row or the second...

This one closes the tags

Code: Select all

<?php
				if (($i % 1 == 1) || ($i % 1 == 3) || ($i % 1 == 5)){
				echo  "</td>";
												 
				}elseif (($i % 1 == 2) || ($i % 1 == 4) || ($i % 1 == 6)){
				echo     "</td>".
						 "</td>".
						 "</tr>";
				}
?>
The whole snipplet is this:

Code: Select all

<?php
			"<table height="100%" width="100%" border="1">";
			
			while ($row = mysql_fetch_assoc($result)) {
			
				// making the tables depending on amount of featured products				
				if (($i % 1 == 1) || ($i % 1 == 3) || ($i % 1 == 5)){
				echo  "<tr>".
						 "<td width="49%">";
						 
				}elseif (($i % 1 == 2) || ($i % 1 == 4) || ($i % 1 == 6)){
				echo     "<td width="1%" bgcolor="#000000">".
						 "<td width="49%">";
				}		 	
								
			    echo "<div align="center"><img src="".$row["image_src"]."" width=125></div>";
				echo "<table cellpadding=2 width="100%"><tr><td class=featureditems>";
				echo "<b>".$row["item_name"]."</b><br>";
				echo "<i>".substr($row["product_description"], 0, 50);
				if (strlen($row["product_description"]) > 50) {
					echo "...";
				}
				echo "</i><br>";
				echo "Our Price: <span class=strikethru>$".$cLink->prepend_zeros($row["item_listprice"])."</span> 
					  <b>$".$cLink->prepend_zeros($cLink->calculate_discount($row["item_price"], $row["item_discount"]))." US</b><br>";
				echo "<br>You save <font color=red>".$cLink->calculate_percent($row["item_listprice"], $row["item_price"])."%</font>.";
				echo "<br>(In Stock: <b>";
				if ($row["number_in_stock"] == 0) {
				echo "NO";
				}
				else {
					echo "YES";
				}
				echo "</b>)";
				if ($row["item_listprice"] == $row["item_price"]){
				echo "<br><b>Note</b>: Free S&H on this item!!";
				}
				echo "</td></tr>";
				echo "<tr><td class=featureditems align=right>";
				echo "<a href="viewitem.php?id=".$row["item_id"].""><img src="images/cart_viewitem.gif" border=0></a> ";
				if ($row["options"]==0) {
				echo "<a href="cart.php?action=add&item=".$row["item_id"].""><img src="images/cart_add.gif" border=0></a>";
				}
				else {
				echo "<a href="viewitem.php?id=".$row["item_id"].""><img src="images/cart_add.gif" border=0></a> ";
				}
				echo "</td></tr>";
				echo "</table><p>";
					
			
				if (($i % 1 == 1) || ($i % 1 == 3) || ($i % 1 == 5)){
				echo  "</td>";
												 
				}elseif (($i % 1 == 2) || ($i % 1 == 4) || ($i % 1 == 6)){
				echo     "</td>".
						 "</td>".
						 "</tr>";
				}
				
				
				
			$i++;
}

echo "</table>";
?>
Help me plz ty

Posted: Sat Feb 28, 2004 4:15 pm
by John Cartwright
nvm i JUst changed the if statements to if i == # instead of finding the remainder dif.