Page 1 of 1

values from array

Posted: Fri Jul 01, 2005 1:34 pm
by ddragas
Hi all

I'm stuck with silly problem.

I'm retriving data from db and depending on query, returns number of data.
On first page is form with one text field with value 'kolicina' and one hidden field with value 'id'.

Code: Select all

<?
echo "<input  name=\"id[]\"  type=\"text\" id=\"kolicina\" size=\"5\" maxlength=\"2\" value=\"$kolicina\">";
echo "<input type=\"hidden\" name=\"id2[]\" value=\"$id\">";
?>


On second page is code wich is getting (POST) values of array

Code: Select all

<?
		if (!empty($_POST['id']))
		{
			echo "Kolicina: " . "<br>\n";
		     		foreach ($_POST['id2'] as $checkbox => $id )
		     			{
						$array = explode ($_POST['id']);
						echo $id . " - " .  $array . "<br>\n";
					}
		}
?>
How to get values from $_POST['id'] (array) ?

Posted: Fri Jul 01, 2005 2:13 pm
by John Cartwright
First of all I recommend you read the documentation on explode. You have to pass a seperator that it can explode into different element arrays.

From that point, you have a few options on retrieving the array values. If you want to loop you can use a foreach() or a for(). If you want to retrieve a single array element then you call the element by its numerical indice.

$array[0] is the first element
$array[1] is the second element, and so on.

Posted: Sat Jul 02, 2005 2:16 pm
by ddragas
resolved Thank you