Jump to content

WHY INSERT fail when I put an IF inside a FOR LOOP ?


vincej

Recommended Posts

Wondering what else you have going on that might change things.  As far as I can tell the array keys should be matching.  Do you get mis-match when not using the sort()?  Also why does you WeightArray show six keys ([5] being the last) when the others all have four?

Link to comment
Share on other sites

Ok - I took off the sort and it brought me back to yesterday where the first row completes perfectly. The non subsequent rows, the Weight value was on the wrong row as well as Order Value not being calculated.

 

 

Here is the Form - You might wonder why I put a value of 0.00 within the 'hidden' Weight variable... that was to ensure that I would not get an empty string being posted and showing up as a empty on the arrays - resulting in everything getting out of synch. The form is produced with CodeIgniter which is just a MVC framework.  it is a mystery to me why there are in some cases 5 values when there are 4 prodID's.  Again, Many Thanks !

 

 

 


<?php // INPUT SCREEN FOR FREEZER STAFF TO APPLY WEIGHTS AND PICK PRODUCTS//

 echo "<br/><H2>Picking List for: ". $customerfullname->firstname." ". $customerfullname->lastname." </H2>"; 
// echo "<h3>Customer Number: ".$pickinglist['0']['CustomerID']."</h3><br/><br/>";
 ?>

<table width="100%" border="1" cellpadding="5">
  <tr>
	<th scope="col">Prod. ID</th>
	<th scope="col">Quantity</th>
	<th scope="col">Name</th>
	<th scope="col">Price lb</th>
	<th scope="col">Weight</th>
	<th scope="col"> Aprox. Expected Total</th>
  </tr>
  <?php  
//print_r($pickinglist);

 echo form_open('admin/pos/finishedorder');
 foreach ( $pickinglist as $value) {  ?>
  <tr>
	<td><?php echo $value['ProdID'] ?></td>
	<td><?php echo $value['Quantity']?></td>
	<td><?php echo $value['Prodname']?></td>
	<td><?php 
	if ($value['Pricelb'] =='0.00'){
	echo "N/A";}
	else echo $value['Pricelb'];
	?></td>
	<td width="20" ><?php

	if ($value['Pricelb'] !== '0.00') {

	$data = array(
			  'name'  => 'weight[]',
			  'id'  => 'weight',
			  'maxlength'   => '6',
			  'size'        => '10',
			   );
	echo form_input($data);
	}
	else echo "N/A";  ?></td>
	<td width="25" align="center"><?php 
	$OrderValue = $value['Price'] * $value['Quantity'];
	echo(number_format($OrderValue,2));?></td>
  </tr>
  <?php
	echo form_hidden('weight[]', '0.00');  
	echo form_hidden('prodid[]', $value['ProdID']);
	echo form_hidden('prodname[]', $value['Prodname']);
	echo form_hidden('orderid[]', $value['OrderID']);
	echo form_hidden('pricelb[]', $value['Pricelb']);
	echo form_hidden('customerid', $value['CustomerID']);
	echo form_hidden('quantity[]',$value['Quantity']) ;
	echo form_hidden('price[]',$value['Price']);
   }   ?>
</table>
<br />
<?php 
echo "<span class=submit_button>".form_submit('submit','Update Order and Send For Payment >>')."</span>";
echo form_close();
?>

 

 

 

 

Link to comment
Share on other sites

Never seen coding like this before.  See something new all the time.

What happens if you comment out line 41 where it adds the input for $data.

echo form_input($data);

I would think there should be a better option for line 49 where you have weight 0.00 and adding the extra input with same name is messing with the array keys.

 

Actually I got that backwards.  Man I could see this if it was a regular form.  Comment out the hidden weight line.  What you need is ONE weight input field regardless of conditions like Pricelb etc.  Still a little hard to see. Sorry

Link to comment
Share on other sites

What about adding the hidden weight to the N/A line.

 

<?php 
	if ($value['Pricelb'] !== '0.00') {
		$data = array(
		'name'  => 'weight[]',
		'id'  => 'weight',
		'maxlength'   => '6',
		'size'        => '10',
		);
		echo form_input($data);
	}else{
		echo form_hidden('weight[]', '0.00') "N/A";
	}
	?>

 

Not sure if this logic also needs to apply to the Pricelb section as well.

<?php 
	if ($value['Pricelb'] =='0.00'){
	echo  form_hidden('pricelb[]', $value['Pricelb']) "N/A";}
	else echo $value['Pricelb'];
	?>

Link to comment
Share on other sites

thanks Drummin - I appreciate that it might be a little hard to follow in Codeigniter so here is the source code uploaded as txt.

 

 

Also I need that input_form() as it generates the text input field.

 

 

I don't take your generosity for granted !

 

 

Thanks .

18344_.txt

Link to comment
Share on other sites

I believe fixing those extra duplicate input fields will fix the problem.  There is also nesting issues with the start form tag and the hidden fields being outside <td> tags.  This copy might be close.  Not having codelighter makes it harder to see so this is untested. 

<?php // INPUT SCREEN FOR FREEZER STAFF TO APPLY WEIGHTS AND PICK PRODUCTS//

 echo "<br/><H2>Picking List for: ". $customerfullname->firstname." ". $customerfullname->lastname." </H2>"; 
// echo "<h3>Customer Number: ".$pickinglist['0']['CustomerID']."</h3><br/><br/>";


echo form_open('admin/pos/finishedorder');
 ?>	
<table width="100%" border="1" cellpadding="5">
  <tr>
	<th scope="col">Prod. ID</th>
	<th scope="col">Quantity</th>
	<th scope="col">Name</th>
	<th scope="col">Price lb</th>
	<th scope="col">Weight</th>
	<th scope="col"> Aprox. Expected Total</th>
  </tr>
  <?php  
//print_r($pickinglist);	
 foreach ( $pickinglist as $value) {  ?>
  <tr>
	<td><?php echo $value['ProdID'] ?></td>
	<td><?php echo $value['Quantity']?></td>
	<td><?php echo $value['Prodname']?></td>
	<td>
	<?php 
	if ($value['Pricelb'] =='0.00'){
	echo  form_hidden('pricelb[]', $value['Pricelb']) "N/A";}
	else echo form_hidden('pricelb[]', $value['Pricelb']) $value['Pricelb'];
	?></td>
	<td width="20" >
	<?php
	if ($value['Pricelb'] !== '0.00') {
		$data = array(
		'name'  => 'weight[]',
		'id'  => 'weight',
		'maxlength'   => '6',
		'size'        => '10',
		);
		echo form_input($data);
	}else{
		echo form_hidden('weight[]', '0.00') "N/A";
	}
	?></td>
	<td width="25" align="center"><?php 
	$OrderValue = $value['Price'] * $value['Quantity'];
	echo(number_format($OrderValue,2));?>

	<?php
	//echo form_hidden('weight[]', '0.00');  
	echo form_hidden('prodid[]', $value['ProdID']);
	echo form_hidden('prodname[]', $value['Prodname']);
	echo form_hidden('orderid[]', $value['OrderID']);
	//echo form_hidden('pricelb[]', $value['Pricelb']);
	echo form_hidden('customerid', $value['CustomerID']);
	echo form_hidden('quantity[]',$value['Quantity']) ;
	echo form_hidden('price[]',$value['Price']);
   }   ?>
	</td>
  </tr>		  
</table>
<br />
<?php 
echo "<span class=submit_button>".form_submit('submit','Update Order and Send For Payment >>')."</span>";
echo form_close();
?>

 

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.