Page 1 of 1

Reading result from Mulitple ListBox

Posted: Tue May 14, 2002 5:27 pm
by terji
I'm having trouble reading results from a listbox like this one:
<select name="listbox" size="6" multiple>

I get the result if only one subject is selected, but when I select more than one I seem to get a random one instead of all I selected.


How can I read all the subjects selected in the listbox:?:

Posted: Tue May 14, 2002 11:41 pm
by jason
In your PHP, use the print_r() function on the listbox variable.

So, if your listbox variable was called $listbox, do this:

Code: Select all

echo "<pre>";
print_r($listbox);
die();
This will show you how to access them.

Posted: Wed May 15, 2002 6:04 am
by terji
I've tried using the code mentioned:

echo "<pre>";
print_r($listbox);
die();

But all it shows is a 'blank' page with this code:

<pre>11

where 11 is one of the 3 items I chose. What am I doing wrong?!?!?


:cry:

Posted: Wed May 15, 2002 6:07 am
by mikeq
So thats a blank page with text on it :D

Posted: Wed May 15, 2002 6:37 am
by jason
Ahh....yes, here is the answer, it's a bugger for sure:

http://www.phpbuilder.com/columns/tim19991124.php3

Posted: Wed May 15, 2002 6:39 am
by denisb
Try next code:
<select name="listbox[]" size="6" multiple>

Watch out for the 0 index!

Posted: Sat Jun 01, 2002 10:10 am
by sycodon
As a new PHP person I have just figured out what's been kicking my ass for the last 2 weeks. The index elements of an array in PHP start with 0, not 1.

'C' guys probaly figured this out, but I'm a COBOL/Powerbuilder guy.


Hope this saves someone weeks of effort.

Posted: Sat Jun 01, 2002 11:08 am
by jason
If you are every unsure what exactly a variable contains:

Code: Select all

&lt;?php
function debug_var ( $variable )
{
    echo "&lt;pre&gt;";
    var_dump($variable);
    echo "&lt;/pre&gt;";
}
?&gt;
And using that function, just call it like this:

Code: Select all

&lt;?php
debug_var($whatever_variable_you_want);
?&gt;