Hi, I have a for each loop, I’m wanting to search the database to see how many rows there are of that persons order (which I have done), then display and number of input fields using a range (which I have done). I then want to put into the value of each of the input fields whatever is in the database…at the moment the same product is being echoed out in all of the range fields. See my code below, apologies for sounding complicated.
<div class="headerTitles">Edit Items in Order</div>
<form action="<?php echo $_SERVER['PHP_SELF']."?section=addtoorder&".$urlCarry ?>" method="post">
<?php
$rowNums = mysql_query("SELECT *,count(*) as total_record FROM order_products WHERE `receipt_id` LIKE '%$ref%'");
$rows = mysql_fetch_array($rowNums);
foreach(range(1,$rows['total_record']) as $num){
include('includes/ordermanage/fields.php');
}
?>
<div class="headerTitles"><input type="submit" value="Submit" name="submit" id="subBtn" /></div>
</form>
fields.php
<!-- BOF Product Info -->
<div class="productInfo" style="width: 540px;">
<div class="prodContain">
<span class="fontField bold">Quant</span>
<input type="text" name="products[<?=$num?>][quantity]" <?=$disabled?> value="<?php echo ($rows) ? $rows['product_quant']:$_POST['products'][$num]['quantity'] ?>" class="prodName" style="width: 20px;" />
</div>
<div class="prodContain">
<span class="fontField bold">Product Description</span>
<input type="text" name="products[<?=$num?>][name]" <?=$disabled?> value="<?php echo ($rows) ? $rows['product_name']:$_POST['products'][$num]['name'] ?>" class="prodName" style="width: 200px" />
</div>
<div class="prodContain">
<span class="fontField bold">Serial Number</span>
<input type="text" name="products[<?=$num?>][serial]" <?=$disabled?> value="<?php echo $_POST['products'][$num]['serial'] ?>" class="prodName" style="width: 70px" />
</div>
<div class="prodContain">
<span class="fontField bold">Stock Number</span>
<input type="text" name="products[<?=$num?>][stock]" <?=$disabled?> value="<?php echo $_POST['products'][$num]['stock'] ?>" class="prodName" style="width: 70px" />
</div>
<div class="prodContain">
<span class="fontField bold">Item Price</span>
<input type="text" name="products[<?=$num?>][price]" <?=$disabled?> value="<?php echo $_POST['products'][$num]['price'] ?>" class="prodName" style="width: 70px;" />
</div>
<!-- BOF New/Used -->
<div style="float: left; width: 650px; margin-top: 5px; color: #444444;"><b>Product Condition</b>
<input type="radio" name="products[<?=$num?>][cond]" value="New" <?php if ($_POST['products'][$num]['cond']=="New") echo "checked"; ?> /> New
<input type="radio" name="products[<?=$num?>][cond]" value="Used" <?php if ($_POST['products'][$num]['cond']=="Used") echo "checked"; ?> /> Used
</div>
<!-- EOF New/Used -->
</div>
<!-- EOF Product Info -->
So in short, think I need to incorporate a while loop in there but unsure of the best way to do this.