Whats wrong with this while loop, I'm so close to getting it right!?

I’m so closing to getting this right. Why are my thumb nails appending like that instead of just displaying the images for that id? First product thumbs are good, but the each item after that appends its thumbnails to the original set.

http://think-outside.com/products/new-products-index-0.php?category=Gear&type=all
[php]<?php
$category = $_GET[‘category’];
$sub_category = $GET[‘sub_category’];
$sub_category = str_replace(’
’, ’ ', $sub_category);
$type = $_GET[‘type’];
$filter = “off”;
$locate = $_SERVER[‘PHP_SELF’] . “?” . $_SERVER[‘QUERY_STRING’];
require_once($_SERVER[‘DOCUMENT_ROOT’] . ‘/db.php’);
db_connect();

$row_count = 0;

// If someone filters the results…

if(isset($_POST[‘submit’]) && $_POST[‘order_by’] != “”) {
$filter_by = $_POST[‘order_by’];
if($type == “all”) {
$sql = “SELECT id, name, size, size_details, price, description, notes, style, add_button, categories, subcategories, types FROM products WHERE categories LIKE ‘%$category%’ && subcategories LIKE ‘%$sub_category%’ status=‘active’ ORDER BY $filter_by”;
}
else {
$sql = “SELECT id, name, size, size_details, price, description, notes, style, add_button, categories, subcategories, types FROM products WHERE categories LIKE ‘%$category%’ && subcategories LIKE ‘%$sub_category%’ && types LIKE ‘%$type%’ && status=‘active’ ORDER BY $filter_by”;
}
}

// Standard Display with No Filtering
else {
if($type == “all”) {
$sql = “SELECT id, name, size, size_details, price, description, notes, style, add_button, categories, subcategories, types FROM products WHERE categories LIKE ‘%$category%’ && subcategories LIKE ‘%$sub_category%’ && status=‘active’ ORDER BY id”;
}
else {
$sql = “SELECT id, name, size, size_details, price, description, notes, style, add_button, categories, subcategories, types FROM products WHERE categories LIKE ‘%$category%’ && subcategories LIKE ‘%$sub_category%’ && types LIKE ‘%$type%’ && status=‘active’ ORDER BY id”;
}
}

$result = db_do($sql);
// If We Have a Result
$rows = db_num_rows($result);
if(db_num_rows($result) > 0 ) {
while(list($id, $name, $size, $size_details, $price, $description, $notes, $style, $add_code, $categories, $subcategories, $types)=db_row($result)) {
$set_sub_id = $sub_id;
$set_type = $type_id;
$main_cat = $cat_id;
$notes = html_entity_decode($notes);
$description = stripslashes($description);
$add_code = html_entity_decode($add_code);
$thumbs = db_do(“SELECT name FROM images WHERE product_id=’$id’ ORDER BY photo_order”);
if(db_num_rows($thumbs) > 0 ) {
$start_row = 1;
$cycle = 0;
while(list($thumb_name)=db_row($thumbs)) {
$thumb_display .= “

  • <a href=”#" rel="$cycle"><img src="/product_images/thumbs/$thumb_name" alt="$img_name" />
  • ";
    					$start_row++;
    					$cycle++;
    				}
    			}
    			$images = db_do("SELECT name FROM images WHERE product_id='$id' ORDER BY photo_order");
    			if(db_num_rows($images) > 0 ) {
    				while(list($img_name)=db_row($images)) { 
    					$img_display = "<img src=\"/product_images/fullsize/$img_name\" alt=\"$img_name\" />";
    					
    				}
    			
    			}
    			else {
    				$img_display = "<img src=\"/images/no-image.jpg\" alt=\"No Image Yet\" />";
    			
    			}
    			
    			// Show Detailed Information
    			if($size_details == "N/A") {
    				$size_details = "";
    			}
    			$add_code = html_entity_decode($add_code);
    			$display .= "<li><div class=\"txts\"><h2>$name</h2>\n";
    			$display .= "<p class=\"price\">" . "$" . "$price</p>";
    			if($add_code == "N/A" || $add_code == "n/a") {
    				$display .= "<p id=\"buttons\"><a href=\"#\" class=\"coming_soon\">Coming Soon</a></p>";
    			}
    			else {
    				$display .= "<p class=\"buttons\"><a href=\"$add_code\" target=\"_blank\">Add To Cart</a></p>";
    				$display .= "(sizes chosen in cart)";
    			};
    			$display .= "<div class=\"details\">$description</div>";
    			
    			// Fix Notes
    			$notes_array = explode(',', $notes);
    			$display .= "<ul>";
    			for($i=0; $i<count($notes_array); $i++) {
    				$display .= "<li>" . $notes_array[$i] . "</li>";
    			}
    			
    			// Move On
    			$display .= "</ul>";
    			$display .= "<p>style no. $style</p>";
    			$display .= "<p class=\"price\">" . "$" . "$price</p>";
    			
    			// Strip Out Sizes :)
    			
    			// This Switches Size Options if Necessary
    			switch ($subcategories) {
    			case "Infant":
        	$possible_sizes = array('3-6','6-12','12-18','18-24');
        	break;
    		case "Toddler":
    			$possible_sizes = array('2T','3T','4T','5T');
    			break;
    		default:
    			"";
    			}
    			$current_sizes = explode(',', $size);
    			if($possible_sizes != 0) {
    				for($x=0; $x<count($possible_sizes);$x++) {
    					if(in_array($possible_sizes[$x], $current_sizes)) {
    						$size_loop .= "<span>$possible_sizes[$x]</span>";
    					}
    					else {
    						$size_loop .= "<span class=\"na\">$possible_sizes[$x]</span>";
    					}
    				}
    			} // close IF
    			else {
    				$size_loop = "";
    			}
    			$display .= "<p id=\"size\">$size_loop</p>";
    			$display .= "<p class=\"buttons\">";
    			if($add_code == "N/A" || $add_code == "n/a") {
    				$display .= "<a href=\"#\" class=\"coming_soon\">Coming Soon</a><a href=\"http://secure.ultracart.com/cgi-bin/UCEditor?merchantId=12THK\">View Cart</a>";
    			}
    			else {
    				$display .= "<a href=\"$add_code\" target=\"_blank\">Add To Cart</a></p>";
    				$display .= "(sizes chosen in cart)</div>
    				<div class=\"imgs\">
    					<div class=\"imgs_wrap\">
    						$img_display
    					</div>
    					<ul class=\"thmbs\">
    						$thumb_display
    					</ul>
    					<div id=\"email-friend\"><a href=\"/email.php?page=$servuri \"><img src=\"/images/subpage/email.gif\" alt=\"Email\" id=\"email-gif\" /> send to a friend</a></div>
    				</div></li>";
    			}
    		} // while loop
    	} // if db_num_rows result
    	
    	else {
    		$filter = "off";
    		$display = "<p>Currently there are no products. Please check back for more additions soon.</p>";
    	}
    

    require_once(’…/include/newest-header.php’);
    ?>

    <?php if($filter != "off") { ?>

    Filter By: --options-- >Name >Size

    <?php } ?>
      <?php echo $display . $end_display; ?>

    Verified Secured by Starfieldtech
    <? require_once('../include/new-footer.php'); ?>[/php]

    Turn Errors on by putting this at the VERY top of the script:

    ini_set('display_errors', 'On');
    error_reporting(-1);

    Thank you, I cleaned up a rouge variable. I will keep error reporting on until resolved. I wish that would have fixed it.

    Any ideas on why these thumbs are appending and not displaying for the one product id?
    Id numbers are now next to images. You can’t see because of the CSS; but the thumbs are appending with the first id at first then the right id appended to that.

    http://think-outside.com/products/new-products-index-0.php?category=Gear&type=all

    It’s this piece of code that needs to display only one id per. Instead it’s appending thumbs to each.
    How do I tell this code to use only the product id above it; in the while loop?

    [php]$thumbs = db_do(“SELECT name FROM images WHERE product_id=’$id’ ORDER BY photo_order”);
    if(db_num_rows($thumbs) > 0 ) {
    $start_row = 1;
    $cycle = 0;
    while(list($thumb_name)=db_row($thumbs)) {
    $thumb_display .= "

  • $id <a href="#" rel="$cycle"><img src="/product_images/thumbs/$thumb_name" alt="$img_name" />
  • ";
    					$start_row++;
    					$cycle++;
    				}
    			}[/php]

    Had to define a variable and clear a variable; so that the old data would be cleared before the next row began.
    Thank you RaythXC!

    Turning errors on helps to locate alot of easily solved problems.

    Sponsor our Newsletter | Privacy Policy | Terms of Service