[PHP] Creating Dropdown Menus From Tables

2004-09-20 Thread Harlequin
Hi all.

Hoping this might be relatively easy...

I'm wondering if I can create a dropdown menu (optionABCDE/option) by 
using a select statement and then populating this using PHP...?

-- 
-
 Michael Mason
 Arras People
 www.arraspeople.co.uk
- 

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



Re: [PHP] Creating Dropdown Menus From Tables

2004-09-20 Thread - Edwin -
On Thu, 16 Sep 2004 13:02:31 +0100
Harlequin [EMAIL PROTECTED] wrote:

 Hi all.
 
 Hoping this might be relatively easy...
 
 I'm wondering if I can create a dropdown menu
 (optionABCDE/option) by using a select statement and
 then populating this using PHP...?

Yes.

Hint: Do a foreach on the result (of the query) then 
inside the loop, just do an 

  echo option$value/option; 

or something like that.

-- 
- E -
copperwalls was here ;)

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



Re: [PHP] Creating Dropdown Menus From Tables

2004-09-20 Thread Marek Kilimajer
Living in the past?
Harlequin wrote:
Hi all.
Hoping this might be relatively easy...
I'm wondering if I can create a dropdown menu (optionABCDE/option) by 
using a select statement and then populating this using PHP...?

Yes, it is relatively easy, and it is answered in virtualy every PHP 
book. I recomend you get one.

Some (pseudo) code:
$res = query(select id, name from table);
while($row = get_result($res)) {
echo option value='$row[id]'$row[name]/option;
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Creating Dropdown Menus From Tables

2004-09-20 Thread James Lobley
On Thu, 16 Sep 2004 13:02:31 +0100, Harlequin
[EMAIL PROTECTED] wrote:
 Hi all.
 
 Hoping this might be relatively easy...
 
 I'm wondering if I can create a dropdown menu (optionABCDE/option) by
 using a select statement and then populating this using PHP...?
 
 --
 -
 Michael Mason
 Arras People
 www.arraspeople.co.uk
 -

for a recent project, I needed an easily adaptable form, with a lot of
different, often changing elements, so I came up with the following
function (amongst others!):

// dropdown boxes
function dropdown($fieldname, $currentvalue='', $onchange='') {
   $var_val = $fieldname . '_val';
   $var_disp = $fieldname . '_disp';
   global ${$var_val}, ${$var_disp};
   if($onchange  '') $onchange = 'ONCHANGE=' . $onchange . '';
   echo('SELECT NAME=' . $fieldname . ' ' . $onchange. '');
   for($loopy=1; $loopy=sizeof(${$var_val}); $loopy++) {
   echo('OPTION VALUE=' . ${$var_val}[$loopy] . '');
   if($currentvalue == ${$var_val}[$loopy]) echo(' SELECTED');
   echo('' . ${$var_disp}[$loopy]);
   }
   echo('/SELECT');
}

I have an include file with the options for each form element -
meaning options can be added or removed easily - an example is:

// Sex
$Sex_val[1] = 'M';
$Sex_disp[1]= 'Male';
$Sex_val[2] = 'F';
$Sex_disp[2]= 'Female';

The function would be called by:
// create dropdown
dropdown('Sex');

// create dropdown, select a matching value
dropdown('Sex',$current_sex);

// create dropdown, select a matching value and run a javascript
function when element is changed
dropdown('Sex',$current_sex, 'checkSex()');

HTH

j
;-}

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