Jump to content

Array with content of multiple="multiple"


Muiter

Recommended Posts

Ok, I´m one step closer.....Now I have this result when using print_r on _POST [calculatie_id0] => Array ( [0] => 1 [1] => 4 [2] => 5 [3] => 6 ) [calculatie_id1] => Array ( [0] => 4 ) [calculatie_id2] => Array ( [0] => 1 [1] => 6 )

Link to comment
Share on other sites

Ok but how to do that? This is what I thought:

for ($i=0; $i<=$aantal_regels; $i++)	{	$calculatie_lst[$i] = $_POST[$calculatie_id][$i];	}

and

<?php for ($i=0; $i<=$aantal_regels_corr; $i++)	{ 		foreach ($calculatie_lst[$i] as $value)		{			echo $value; 		}	?>

Link to comment
Share on other sites

the second condition in a for loop requires a number. Typically when searching through arrays, one would tend to use the length method to have the for loop check through all index's.

for (i=0; i<=myArray.length; i++){  //check for what you're looking for};

Link to comment
Share on other sites

myArray.length is for javascript, count($myArray) is for PHP
haha, woops!hopefully the OP gets the idea :)
Link to comment
Share on other sites

One step closer again.

	<?php 		print_r($calculatie_id); 		for ($i=0; $i<=$aantal_regels_corr; $i++) 	{ 	?>  	<tr> 		<td> 				<?php 		foreach ($calculatie_id[$i] as $value) 		{ 			echo $value; 		} 	?>

print_r($calculatie_id); gives Array ( [0] => Array ( [0] => 4 [1] => 6 ) [1] => Array ( [0] => 1 [1] => 5 ) [2] => Array ( [0] => 5 [1] => 6 ) [3] => )But when using the foreach I only get 46 :)

Link to comment
Share on other sites

where exactly is the value for $aantal_regels_corr coming from? in the for loop.
<?phpif ($aantal_regels == ""){	$aantal_regels = 5;}$aantal_regels_corr = $aantal_regels-"1";$aantal_regels_oud = $aantal_regels;?>

This part works for the rest of my form.

Link to comment
Share on other sites

are you trying to subtract 1 or a string with the value "1"? building off what dsonesuk said, what is the value of $aantal_regels_corr at the time of the for loop? Also, just emphasize specificity, it should be you printing out the value using print_r or something, not just assuming it should be something you're expecting it to be (or else it would be working).

Link to comment
Share on other sites

if ($aantal_regels == ""){	$aantal_regels = 5;}$aantal_regels_corr = $aantal_regels-"1";$aantal_regels_oud = $aantal_regels;

Where is the value for $aantal_regels coming from?What we're really getting at here is that somewhere in your code $aantal_regels_corr is being set to 0. Which means that your loop...
for ($i=0; $i<=$aantal_regels_corr; $i++)	{	?>  	<tr>		<td>				<?php		foreach ($calculatie_id[$i] as $value)

...is only going to run once.

Link to comment
Share on other sites

Many thanks for helping me out this far but all the examples I try to implement are not working.I have been trying this script for over 2 weeks now. It seems I'm going all the wrong way.I have put my code online at www.pws.nl/downloads/sp_offerte_add.rar. It must be easier then what I'm writing in the code right now.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...