SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Getting Check box values using array in PHP

Many times we have to display a list of names or records for consideration and out of which user can select any number of records for further action. Here we may not know exactly how many records will be displayed as some time based on different conditions records will be collected from a table. So we can list the records with a checkbox by the side of it and user can select any number of recodes. We will have one unique id associated with each record and that will be used as value of the check box. Here is the code to display a list and then you can select and submit to see the result.

This is a server side solution and we can get the array value using client side JavaScript we can also get the value of the array of checkboxes.
Note that if in your server settings global variables is set to OFF then you have to take care for that.


 John  Mike  Rone
 Mathew  Reid  Simon

while (list ($key,$val) = @each ($box)) {
echo "$val,";
}

echo "<form method=post action=''>";
echo "<table border='0' cellspacing='0' style='border-collapse: collapse' width='100' >
<tr bgcolor='#ffffff'>
<td width='25%'><input type=checkbox name=box[] value='John'></td>
<td width='25%'>&nbsp;John</td>
<td width='25%'><input type=checkbox name=box[] value='Mike'></td>
<td width='25%'>&nbsp;Mike</td>
<td width='25%'><input type=checkbox name=box[] value='Rone'></td>
<td width='25%'>&nbsp;Rone</td>
</tr>
<tr bgcolor='#f1f1f1'>
<td width='25%'><input type=checkbox name=box[] value='Mathew'></td>
<td width='25%'>&nbsp;Mathew</td>
<td width='25%'><input type=checkbox name=box[] value='Reid'></td>
<td width='25%'>&nbsp;Reid</td>
<td width='25%'><input type=checkbox name=box[] value='Simon'></td>
<td width='25%'>&nbsp;Simon</td>
</tr>

<tr><td colspan =6 align=center><input type=submit value=Select></form></td></tr>
</table>";

In ASP similar script to collect checkbox values of a form is available here.

Discuss this tutorial at forum


Further readings
 PHP array
array : Creating an Array
array_diff Difference of two arrays
array_count_values counting the frequency of values inside an array
count : sizeof Array Size or length
array_push : Adding element to an Array
array_sum : Array Sum of all elements
Displaying the elements of an array
Array checkbox
in_array : IN Array to search for elements inside an array
array_rand : Random elements of Array
array_unique : Array Unique values
Breaking of strings to create array using split command
unset : Deleting elements of an array by using its key
sort: Simple sorting of PHP array
rsort: Reverse sorting of PHP array
asort: Maintaining index of the elements after sorting
arsort: Sorting in reverse order for a PHP array
ksort: Array key Sorting in PHP
krsort: Array reverse key Sorting in PHP
usort: Sorting array by using user defined function














 

Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.

Scripts
PHP
JavaScript
PHP Tutorial Index
Array Functions
array_diff
array_count_values
array_size
array_push
array_sum
in_array
array_rand
array_unique
Split String
unset (delete)
sort
rsort
asort
arsort
ksort
krsort
usort
Displaying elements
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
PHP Tutorials
Date & Time
Array
String Functions
Math Functions
Form Handling
File Handling
Comment Posting
Content Management
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.