Displaying Info In Tables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Displaying Info In Tables

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

nvm i JUst changed the if statements to if i == # instead of finding the remainder dif.
Post Reply