Avatar of echocpt
echocpt
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Help looping results after initial call

Hi,

I feel i am missing something blindingly obvious but i just can't get the code below to work. What i am trying to do is pull the results of a query and display them on a page. However if there are any options for the product being displayed they should be added into the select menu. I have got it working so that the select menu displays the last 3 options of a possible 4, but no mater what i do I can't get it to display the first result.

I believe it could be down to me calling on the query twice?

Thanks,
Alex
<?php
include ('./includes/product_functions.inc.php');

$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
?>

<div id="content-wrapper">
	<div id="content-container" class="full-radius">
		<ul class="product-navigation">
			<li><a href="#" class="left-radius-6px left">Notebooks</a></li>
			<li><a href="#">Exercise Books</a></li>
			<li><a href="#">Sketchbooks</a></li>
			<li><a href="#">Diaries &amp Journals</a></li>
			<li><a href="#" class="right-radius-6px">Sale Items</a></li>
		</ul>
		
		<div id="header-text">
			<h1 class="header-text-detail"><?php echo $row['product_title']; ?></h1>
		</div>
		
		<div id="detail-wraper">
			<div id="left">
				<div class="image-container"><img src="images/test_product_detail.png" alt="EcoBook" /></div>
				<div class="mini-image-container"></div>
				<div class="mini-image-container"></div>
				<div class="mini-image-container"></div>
			</div>
			<div id="right">
				<h1>The Information</h1>
				<p><?php echo $row['product_long_description']; ?></p>
				<h1>The Quick Specs</h1>
				<p><?php echo $row['product_short_description']; ?></p>
				<h1>Price</h1>
				<span class="price"><?php echo get_price($row['product_price'], $row['sale_price']); ?></span>
				
				<form name="" action="/cart.php" method="post">
					<input type="hidden" name="pid" value="<?php echo $row['product_id']; ?>" />
					<?php
					if(!is_null($row['colour_id'])) {
						
					$colour_list = "";
					while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
        				$colour_id = $row['colour_id'];
						$colour_title = $row['colour_title'];
						$colour_list .= "<option value=\"$colour_id\">$colour_title</option>\n";
					}
					
					echo "<select name=\"colid\"/>$colour_list</select>";
						
						
					} else {
						echo '<input type="hidden" name="coid" value="NULL" />';
					}						
					?>
					
					<input type="hidden" name="action" value="add" />
					<input type="submit" value="Add to Bag" />
					<div class="buttons">
						<a href="#" class="button full-radius">
							<span class="bag">Add to Bag</span>
						</a>
						<a href="#" class="button full-radius">
							<span class="">Add to Wishlist</span>
						</a>
					</div>
				</form>
			</div>
		</div>
		
	</div>
</div>

Open in new window

PHPMySQL Server

Avatar of undefined
Last Comment
echocpt

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
StingRaY

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
echocpt

ASKER
Brilliant, knocked it on the head in one. Always the simple ones :)

Thanks,
Alex
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck