Use checkboxes to display selected records

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
manton
Forum Newbie
Posts: 10
Joined: Fri Apr 27, 2007 8:27 am
Location: Athens

Use checkboxes to display selected records

Post by manton »

Hello,
I have a table on a form which contains records that can be multiple selected by checkboxes. A submit button sucessfully sends the record IDs of the checked records to the next page.

I want to display the records that were selected via the checkboxes, but the problem is that I get only the first of them.

Any help would be really appreciated, thanks
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

you need to change your checkbox to be an array

Code: Select all

<input type="checkbox" name="fieldname[]" value="foo">
<input type="checkbox" name="fieldname[]" value="bar">
<input type="checkbox" name="fieldname[]" value="foobar">

<?php
//on submit
echo '<pre>';
print_r($_POST['fieldname'])
?>
Which will provide you an array of your values for fieldname[]
Post Reply