-----Oorspronkelijk bericht-----
Verzonden: Friday, March 29, 2002 11:44 AM
Onderwerp: failure notice

Hi. This is the qmail-send program at pb1.pair.com.
I'm afraid I wasn't able to deliver your message to the following addresses.
This is a permanent error; I've given up. Sorry it didn't work out.

timed out waiting for confirmation that sender is real
I'm not going to try again; this message has been in the queue too long.

--- Below this line is a copy of the message.

Return-Path: <[EMAIL PROTECTED]>
Received: (qmail 87144 invoked by uid 1007); 22 Mar 2002 09:43:56 -0000
Reply-To: "Marij B." <[EMAIL PROTECTED]>
From: "Marij B." <[EMAIL PROTECTED]>
References: <[EMAIL PROTECTED]>
Subject: Re: Fill select boxes with dependent data from a database. How?
Date: Fri, 22 Mar 2002 10:43:59 +0100
Lines: 209
Organization: Centric
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400

You're lucky,

I had the same problem, needing 2 synced pulldown menus, but I found a
I add 2 parts:
1) the function
2) an example to make the arrays

part 1: the function


# synched pulldown menu's:

 Creates two synched pull down menus with two name-value paired arrays.
 The code of these pull down menus is returned as 2 strings ($pd1 and $pd2)
 so you can place them where ever you want
 must be placed between already existing form elements, and only once on a

So far used as:
array_groups: $klanten[$row_pd[id]] = $row_pd[naam];
array_members: $klant_cont_combo[$row_pd2[klanten_id]][$row_pd2[id]] =

Needs PHP v4.06 at least. For PHP v4.1 or higher change the function
key_exists() in array_key_exists()

function create_synched_pulldowns($array_groups, $array_members, $form_name,
$pd_name1, $pd_name2) {
 $array_groups2 = $array_groups;
 $pd1 = "";
 # this must be outputted before the first pull down menu
 $pd1 .= "\n\n<!-- create_synched_pulldowns pd1 -->\n\n";
 $pd1 .= "<SCRIPT LANGUAGE=\"JavaScript\">
 <SCRIPT LANGUAGE=\"JavaScript1.1\">
 if (typeof(Option)+\"\" != \"undefined\") v=true;
 <SCRIPT LANGUAGE=\"JavaScript\"><!--
  a=new Array(22);

 var catsIndex = -1;
 var itemsIndex;

 if (v) { // ns 2 fix

  function newCat(){
   a[catsIndex] = new Array();
   itemsIndex = 0;

  function O(txt,url) {
   a[catsIndex][itemsIndex]=new myOptions(txt,url);

  function myOptions(text,value){
   this.text = text;
   this.value = value;

  // populate array for pd's

  # empty cat voor blank 1st values
  $pd1 .= "\nnewCat();\n";
  $pd1 .= "O(\"Maak evt. een keuze\", \"\")\n";

  # process the $array1 and $array2 to polulate the array used by js

  while (list($key, $val) = each($array_groups)) {

   # Now fill the array with models for each make
   $pd1 .= "\nnewCat();\n";

   if(array_key_exists($key, $array_members)) {
    while (list($key2, $val2) = each($array_members[$key])) {
     # format: O(label, value)
     $pd1 .= "O(\"$val2\", \"$key2\")\n";
   } else { # echo "No contact found for this company" or something
    $pd1 .= "O(\"Geen gegevens gevonden\", \"\")\n";

   $pd1 .="\n";

  # continue creation of the 1st pull down menu string
  $pd1 .="
 } // end if (v)

 function relate(j) {
   with (document.$form_name.$pd_name2) {
    for(i=options.length-1;i>0;i--) options[i] = null; // null out in
reverse order (bug workaround)
     options[i] = new Option(a[j][i].text,a[j][i].value);
     options[0].selected = true;

 // BACK BUTTON FIX for ie4+- or
 function IEsetup(){
  if(!document.all) return;
  IE5 = navigator.appVersion.indexOf(\"5.\")!=-1;
  if(!IE5) {
   for (i=0;i<document.forms.length;i++) {

 window.onload = IEsetup;


 $pd1 .="<SELECT NAME=\"$pd_name1\" ID=\"$pd_name1\"
onChange=\"relate(this.selectedIndex)\" class=\"pulldownmenus\">";

 # fill menu 1
 $pd1 .="<OPTION VALUE=\"\">Maak een keuze</OPTION>\n";
 while (list($key, $val) = each($array_groups2)) {
  $pd1 .="<OPTION VALUE=\"$key\">$val</OPTION>\n";

 $pd1 .="</SELECT>\n";

 # start creation pull down menu 2
 $pd2="<SELECT NAME=\"$pd_name2\" ID=\"$pd_name2\" class=\"pulldownmenus\">
 <OPTION VALUE=\"\">Maak een keuze</OPTION>

 $pd = array();
 $pd[1] = $pd1;
 $pd[2] = $pd2;
 return $pd;

# this function prints the elements of an array
function print_array($array) {
 if (gettype($array) == "array") {
  echo "<ul>\n";
  while (list($index, $subarray) = each($array) ) {
   echo "<li>$index <code>=&gt;</code> \n";
   echo "</li>\n";
  echo "</ul>\n";
 } else {
 echo $array;

part 2:make the arrays
    #MARKTSEGMENTEN: Get entries listed in table for marktsegmenten
    $query_pd = "SELECT id, naam FROM marktsegment1 ORDER BY naam";
    $result_pd = mysql_db_query($database, $query_pd, $connection) or die
("Could not execute query_pd: $query_pd. " . mysql_error() );
    $klanten = array();
    while ($row_pd = mysql_fetch_array($result_pd)) {
     $klanten[$row_pd[id]] = $row_pd[naam];

    $query_pd2 = "SELECT id, naam, marktsegment1_id FROM marktsegment2 ORDER
BY marktsegment1_id, naam";
    $result_pd2 = mysql_db_query($database, $query_pd2, $connection) or die
("Could not execute query_pd2: $query_pd2. " . mysql_error() );
    $klant_cont_combo = array();
    while ($row_pd2 = mysql_fetch_array($result_pd2)) {
     # fill an array with the companies contacts
     $klant_cont_combo[$row_pd2[marktsegment1_id]][$row_pd2[id]] =

    $pd = create_synched_pulldowns($klanten, $klant_cont_combo, $form_name,
"ms1", "ms2");
    #echo $pd[1];
    #echo "&nbsp;";
    #echo $pd[2];

Hope this is what you were lokking for.
Let me know if it helped

Marij Bellen

The information included in this message is personal and/or confidential and
intended exclusively for the addressees as stated. This message and/or the
accompanying documents may contain confidential information and should be
handled accordingly. If you are not the intended reader of this message, we
urgently request that you notify Centric immediately and that you delete
this e-mail and any copies of it from your system and destroy any printouts
It is forbidden to distribute, reproduce, use or disclose the information in
this e-mail to third parties without obtaining prior permission from
Centric. We expressly point out that there are risks associated with the use
of e-mail. Centric and the companies within the group shall not accept any
liability whatsoever for damage resulting from the use of e-mail. Legally
binding obligations can only arise for Centric by means of a written
instrument, signed by an authorized representative of Centric. 

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

Reply via email to