Jump to content

Help understanding this loop


evolooshun

Recommended Posts

Admittedly Im a novice and Ive inherited the following code that I need to modify.  It currently propagates the data into 2 columns which filled the content table however it will look better if I can make it 3 columns wide.  I think I understand how the code works but Im not sure how to modify it to get it to behave like I desire.

Link to website:

http://estore.advancedlabeling.com

This is the code in question:

if(!$rows > "0"){			
		print("<p>Sorry no product categories exist at this time.  Please check back soon!</p>");
	} else {

		$showDivide="";

		for($index=0; $index < $rows; $index++){

			$record = mysql_fetch_array($result);
			$catName = $record["catName"];	
			$description = nl2br($record["description"]);	
			$smPic = $record["smPic"];	
			$thisID = $record["entryID"];

			if($smPic != ""){
				$thisPic = "media/prodPics/";
				$thisPic .= $smPic;
				if(!file_exists("$thisPic")){ $smPic=""; }
			}//eof if($smPic != "")

			$catLink = "subCat.php?catID=";	
			$catLink .= $thisID;	

			if($thisID  != ""){
				$query2  = "SELECT DISTINCT * ";
				$query2 .= "FROM prodcats ";
				$query2 .= "WHERE subcatID = '" . $thisID . "' ";
				$query2 .= "ORDER BY orderID, catName ";
				//print("Query2: $query2<br />");
				$result2 = mysql_query($query2, $sqlLink);
				$rows2 = mysql_num_rows($result2);
				if($rows2) { 


			?>

			<div class="product2">
				<table width="100%" cellpadding="0" cellspacing="0" border="1">
					<tr>
						<td align="center" class="productLabel"><div class="bold"><a href="pages/<?php print("$catLink"); ?>"><?php print("$catName"); ?></a></div></td>
            			</tr>
            			<tr>
              				<td align="center" class="cartLabel"><a href="pages/<?php print("$catLink"); ?>"><?php if($smPic != ""){ ?><img src="<?php print("$thisPic"); ?>" alt="<?php print("$catName"); ?>" /><?php } ?></a></td>
            			</tr>
            			<tr>
              				<td class="cartLabel"><p>
              				<?php if($description != ""){ print("Description:<br />$description<br />"); } ?>
              				
              				<?php

						if($rows2 > "0"){
						  print("<ul>");
							for($f=0; $f < $rows2; $f++){

								$record2 = mysql_fetch_array($result2);
								$subcatName = $record2["catName"];
								$subcatID = $record2["entryID"];	

								$subcatLink = "prodList.php?catID=";	
								$subcatLink .= $thisID;
								$subcatLink .= "&subcatID=";
								$subcatLink .= $subcatID;	

								if($subcatID != ""){
									print('<li><a href="pages/' . $subcatLink . '">' . $subcatName . '</a></li>');
								}//eof - if($subcatID != "")

							}//eof for loop $f
						  print("</ul>");
						}//eof - if($rows2 > "0")
						?>
              				              				
              				</p></td>
            			</tr>
          			</table>
       		 	</div>
        
			<?php
			if($showDivide != ""){
				$showDivide = "";
				print('<div class="clear"></div>');
			} else { $showDivide = "1"; }
			}//eof - if($row2)
			}//eof - if($thisID  != "")
        	}//eof for loop $index
        
		if($showDivide != ""){
			$showDivide = "";
			print('<div class="clear"></div>');
		} else { $showDivide = "1"; }
        	
        }//eof - if($rows > "0")
        ?>        

 

I believe the section I need to modify is the following "loop" event that determins to print('<div class="clear"></div>'); if theres no more data.

<?php
			if($showDivide != ""){
				$showDivide = "";
				print('<div class="clear"></div>');
			} else { $showDivide = "1"; }
			}//eof - if($row2)
			}//eof - if($thisID  != "")
        	}//eof for loop $index
        
		if($showDivide != ""){
			$showDivide = "";
			print('<div class="clear"></div>');
		} else { $showDivide = "1"; }
        	
        }//eof - if($rows > "0")
        ?> 

 

If someone could shed light on this issue it would be greatly appreciated.  Please keep in mind, layman's terms.  Thanks!!!

 

Link to comment
Share on other sites

If you want to make a cell span more than one column, which is what you said you wanted to do, use the "colspan" attribute: http://www.w3.org/TR/html401/struct/tables.html#adef-colspan

 

This code is inherently wrong because it is outputting HTML in little bits, mixed with programming logic. I suggest you replace this code when you can to make it more accessible to other developers.

Link to comment
Share on other sites

Cell Span doesn't apply to my issue because these are floating tables.  Ive made the table width a bit smaller so a third should fit on a row before going to the next row, thus the added column.  If you click on the picture in the table it takes you to a subCat page which IS displaying properly.

 

Any ideas?

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.