Current location: Hot Scripts Forums » Programming Languages » PHP » fill items in a combo-box on the fly


fill items in a combo-box on the fly

Reply
  #1 (permalink)  
Old 06-27-03, 06:27 AM
boskyvora boskyvora is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
fill items in a combo-box on the fly

Hi there,

I have a php page wherein when the page is loaded it should fetch records from the database and add the records in a combo-box.

Getting the record is not a problem but just assigning the value to the combo-box is giving me a tough time. Any guesses how it can be done.

Regards
Bosky
Reply With Quote
  #2 (permalink)  
Old 06-27-03, 08:07 AM
nd2 nd2 is offline
Wannabe Coder
 
Join Date: Jun 2003
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
yeah, ive wrote a small php program below, just put your combo list entrys in the $mycombolist array and the result value of the field store in the variable $myvalue or rename that variable to the value of your out put, this will then select the field that it matchs.
have fun.

PHP Code:

<?php

// untested

$mycombolist = array(
"selectboxname" => "selectboxvalue",
"selectboxname2" => "selectboxvalue2"
);

?>
<select size="1" name="D1">

<?php

foreach (array_keys($mycombolist) as $i) {
// matched
if ($mycombolist[$i] == $myvalue) {
echo 
'<option selected value="'.$mycombolist[$i].'">'.$i.'</option>';
}

// didnt match
else {
echo 
'<option value="'.$mycombolist[$i].'">'.$i.'</option>';
}

}
?>
__________________
IonCMS (Coming Soon.)
http://ioncms.com
--
Ncaster (Free php/mysql cms)
http://ncaster.cjb.net

Last edited by Christian; 05-12-06 at 12:59 PM.
Reply With Quote
  #3 (permalink)  
Old 06-27-03, 05:31 PM
ChristGuy ChristGuy is offline
Operations Support Develo
 
Join Date: Jun 2003
Location: Rivonia, South Africa
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
I'm guessing you're looking for something like:
PHP Code:

  $Result MySQL_DB_Query("DBName""SELECT * FROM Clients");


  echo 
"<SELECT NAME='clientid'>";

  while (
$Row MySQL_Fetch_Array($Result))
  {
    echo 
"<OPTION VALUE='" $Row["ClientID"] . "'>" $Row["ClientName"] . "</OPTION>";
  }

  echo 
"</SELECT>";

  
MySQL_Free_Result($Result); 
__________________
Till We Meet Again...
Clifford W. Hansen
Aspivia (Pty) Ltd

"We Have Seen Strange Things Today!" Luke 5:26
Reply With Quote
  #4 (permalink)  
Old 05-11-06, 11:58 AM
sldghmr sldghmr is offline
New Member
 
Join Date: May 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
I've used the below script to populate my drop down box. What I'd like to do is have my page (which upon opening has all the fields blank) and then populate all the fields based on the selection made from the drop down box. So, I guess the question is how to pass that onto the rest of the form. Am I on the right track with this or is there a different way I should be doing it?

TIA
Ray
PHP Code:

$Result MySQL_DB_Query("DBName""SELECT * FROM Clients");


  echo 
"<SELECT NAME='clientid'>";

  while (
$Row MySQL_Fetch_Array($Result))
  {
    echo 
"<OPTION VALUE='" $Row["ClientID"] . "'>" $Row["ClientName"] . "</OPTION>";
  }

  echo 
"</SELECT>";

  
MySQL_Free_Result($Result); 

Last edited by Christian; 05-12-06 at 01:00 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
700-800 items in a javascript menu dbineb1 JavaScript 0 10-10-03 04:58 PM
reset combo box sasi ASP 1 09-19-03 06:22 PM
Nefarious PHP Seeking a few jobs to fill nefariousphp Job Offers & Assistance 4 09-17-03 09:05 AM
retrieve data from combo box sasi ASP 1 09-03-03 06:16 PM
Load from database to a combo box sasi ASP 1 08-24-03 09:30 PM


All times are GMT -5. The time now is 08:04 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.