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!
I have a select box where I show the names of each category and I want to pass the id of the selected category to my script.php page. The problem is that $id_category gets only the id of the last category on my database. I know that this happens due to the while loop. I just don't know how to fix the situation.
One way to do this is append "[]" to the name of the form element, and move it inside the loop (so it will output multiple times). All the values will be sent as an array.
The other way is to build up your own array and serialize it (or build up a comma delimited string, and output that as the value).
$array = array();
while ($row = mysql_fetch_assoc($result)) {
$array[] = $row;
# this part passes an array over GET/POST parameters. On the next page $_GET['array'] will be the same as $array
$id = 'whatever';
echo '<input type="hidden" name="array[]" value="' . $id . '" />';
}
print_r($array);