values from array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

values from array

Post 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) ?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

resolved Thank you
Post Reply