Hi,

first you need connect to the database y attach on this example a litle
extension class of Pear DB class. I suppose that your case use mysql
database.

this is an example: 
--------------------------------------------------------------------
<?

require_once db.clas.php

$DB = array ();
$DB['type'] = 'mysql';
$DB['host'] = '10.10.1.7';
$DB['user'] = 'youruser';
$DB['password'] = 'yourpassword';
$DB['dbname'] = 'yourdb';

function myCheck($op){
 global $DB;
 $mdb = new mdb;
 $out = "";
 $q = "select * from checkbox_table order by groups_name";
 
 if($db->db_dbArray($DB, $q)){
   for($i=0;$i<count($db->_db['data']);$i++){
     $checked = ($db->_db['data'][$i]['groups_id'] == $i) ? "checked" :
"";
     $out .= "<input name='sel_group[]' type='checkbox'
value='{$db->_db['data'][$i]['groups_id']}'
{$checked}>{$db->_db['data'][$i]['groups_name']}<BR>";
   }
 }
 return $out;
}
?>

<form name="checkbox" method="post" action="<?= $_SERVER['PHP_SELF']?>"
ENCTYPE="multipart/form-data">
<?= myCheck($_REQUEST['sel_group']) ?>
</form>

--------------------------------------------------------------------


On Tue, 2006-02-21 at 20:52 -0500, Jeff Broomall wrote:
> Good evening.
> 
> I'm sure this is something easy so I'm hoping you can simply steer me to a 
> good source.
> 
> I simply need to create a Checkbox list using data from my "groups" table.
> 
> I have a table with two fields:
>  1)  groups_id
>  2)  groups_name
> 
> The data contained is simple:
> 
>  groups_id groups_name
>  ----------- ----------------
>      1    Group A
>      2    Group B
>      3    Group C
>      4    Group D
> 
> I would like to dynamically create a checkbox selection similar to:
> 
> <input name="sel_group[]" type="checkbox" value="1">Group A<BR>
> <input name="sel_group[]" type="checkbox" value="2">Group B<BR>
> <input name="sel_group[]" type="checkbox" value="3">Group C<BR>
> <input name="sel_group[]" type="checkbox" value="4">Group D<BR>
> 
> So I need a script that'll take this information from the groups table
> and create the above.  Can you help?
> 
> As I look at this, I believe I'm going to need to create an array for my 
> final "report."  So I just added the [] after sel_group.
> 
> Thanks.
> 
> Ward 
> 
-- 
---------------------------------------------------------------------------------
Luis Morales 
Consultor de Tecnologia
Cel: +(58)416-4242091
---------------------------------------------------------------------------------
"Empieza por hacer lo necesario, luego lo que es posible... y de pronto
estarás haciendo lo imposible"
---------------------------------------------------------------------------------

Attachment: db.class.php
Description: application/php

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to