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.

To remove one extra , at the end of the output we used rtrim function.
 John  Mike  Rone
 Mathew  Reid  Simon

// This is to collect box array value as global_variables is set off in PHP5 by default
while (list ($key,$val) = @each ($box)) {
$str=$str. "$val,";
$str=rtrim($str,','); // To remove last char using rtrim
echo "<pre><code>$str</code></pre>";

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 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><td colspan =6 align=center><input type=submit

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




Good one thanks

Post Comment This is for short comments only. Use the forum for more discussions.

HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2017 All rights reserved worldwide Privacy Policy Disclaimer