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
terji
Forum Commoner
Posts: 37 Joined: Tue May 14, 2002 5:27 pm
Location: Denmark
Post
by terji » Tue May 14, 2002 5:27 pm
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
jason
Site Admin
Posts: 1767 Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:
Post
by jason » Tue May 14, 2002 11:41 pm
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.
terji
Forum Commoner
Posts: 37 Joined: Tue May 14, 2002 5:27 pm
Location: Denmark
Post
by terji » Wed May 15, 2002 6:04 am
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?!?!?
mikeq
Forum Regular
Posts: 512 Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland
Post
by mikeq » Wed May 15, 2002 6:07 am
So thats a
blank page with text on it
denisb
Forum Newbie
Posts: 2 Joined: Tue May 14, 2002 8:33 am
Post
by denisb » Wed May 15, 2002 6:39 am
Try next code:
<select name="listbox[]" size="6" multiple>
sycodon
Forum Newbie
Posts: 1 Joined: Sat Jun 01, 2002 10:10 am
Post
by sycodon » Sat Jun 01, 2002 10:10 am
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.
jason
Site Admin
Posts: 1767 Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:
Post
by jason » Sat Jun 01, 2002 11:08 am
If you are every unsure what exactly a variable contains:
Code: Select all
<?php
function debug_var ( $variable )
{
echo "<pre>";
var_dump($variable);
echo "</pre>";
}
?>
And using that function, just call it like this:
Code: Select all
<?php
debug_var($whatever_variable_you_want);
?>