art-d-sign
-


Hinweise


Antwort
 
LinkBack Themen-Optionen Thema durchsuchen Thema bewerten
Alt 19.06.2003, 02:01   #1
TP-Member
 
Registriert seit: Apr 2002
Ort: kuwait
kupilot macht alles soweit korrekt
Unhappy

dependant dropdown lists


Hallo

schaut euch mal diesen macromedia technote es ist fuer dynamic dropdown lists fuer ASP & javascript.

http://www.macromedia.com/support/ul...ic_listbox.htm


Ich versuechte es nachzuahmen nuer in PHP & Javascript & MySQL , allerdings gibt es da etwas nicht richtig , koennt ihr mal nachschauen und mir wo die fehler liegt:

<?php require_once('Connections/connLogbook.php'); ?>
<?php
mysql_select_db($database_connLogbook, $connLogbook);
$query_rsType = "SELECT * FROM atype";
$rsType = mysql_query($query_rsType, $connLogbook) or die(mysql_error());
$row_rsType = mysql_fetch_assoc($rsType);
$totalRows_rsType = mysql_num_rows($rsType);

mysql_select_db($database_connLogbook, $connLogbook);
$query_rsAreg = "SELECT * FROM areg";
$rsAreg = mysql_query($query_rsAreg, $connLogbook) or die(mysql_error());
$row_rsAreg = mysql_fetch_assoc($rsAreg);
$totalRows_rsAreg = mysql_num_rows($rsAreg);
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- Dynamic Dependent List box Code for *** JavaScript *** Server Model //-->
<script language="JavaScript">
<!--

var arrDynaList = new Array();
var arrDL1 = new Array();

arrDL1[1] = "atype"; // Name of parent list box
arrDL1[2] = "form1"; // Name of form containing parent list box
arrDL1[3] = "areg"; // Name of child list box
arrDL1[4] = "form1"; // Name of form containing child list box
arrDL1[5] = arrDynaList;

<%
var txtDynaListRelation, txtDynaListLabel, txtDynaListValue, oDynaListRS;

txtDynaListRelation = "atypeID" // Name of recordset field relating to parent
txtDynaListLabel = "areg" // Name of recordset field for child Item Label
txtDynaListValue = "aregID" // Name of recordset field for child Value
oDynaListRS = rsAreg // Name of child list box recordset

var varDynaList = -1;
var varMaxWidth = "10";
var varCheckGroup = oDynaListRS.Fields.Item(txtDynaListRelation).Value;
var varCheckLength = 0;
var varMaxLength = 0;

while (!oDynaListRS.EOF){

if (varCheckGroup != oDynaListRS.Fields.Item(txtDynaListRelation).Value) {
varMaxLength = Math.max(varCheckLength, varMaxLength)
varCheckLength = 0;
}
%>
arrDynaList[<%=(varDynaList+1)%>] = "<%=(oDynaListRS.Fields.Item(txtDynaListRelation).Value)%>";
arrDynaList[<%=(varDynaList+2)%>] = "<%=(oDynaListRS.Fields.Item(txtDynaListLabel).Value)%>";
arrDynaList[<%=(varDynaList+3)%>] = "<%=(oDynaListRS.Fields.Item(txtDynaListValue).Value)%>";
<%

if (oDynaListRS.Fields.Item(txtDynaListLabel).Value.length > varMaxWidth.length) {
varMaxWidth = oDynaListRS.Fields.Item(txtDynaListLabel).Value;
}
varCheckLength = varCheckLength + 1;
varDynaList = varDynaList + 3;
oDynaListRS.MoveNext();
}
varMaxLength = Math.max(varCheckLength, varMaxLength)
%>


//-->
</script>

<!-- End of object/array definitions, beginning of generic functions -->

<script language="JavaScript">
<!--
function setDynaList(arrDL){

var oList1 = document.forms[arrDL[2]].elements[arrDL[1]]
var oList2 = document.forms[arrDL[4]].elements[arrDL[3]]
var arrList = arrDL[5]

clearDynaList(oList2);

if (oList1.selectedIndex == -1){
oList1.selectedIndex = 0;
}

populateDynaList(oList2, oList1[oList1.selectedIndex].value, arrList);
return true;
}

function clearDynaList(oList){

for (var i = oList.options.length; i >= 0; i--){
oList.options[i] = null;
}

oList.selectedIndex = -1;
}

function populateDynaList(oList, nIndex, aArray){

for (var i = 0; i < aArray.length; i= i + 3){
if (aArray[i] == nIndex){
oList.options[oList.options.length] = new Option(aArray[i + 1], aArray[i + 2]);
}
}

if (oList.options.length == 0){
oList.options[oList.options.length] = new Option("[none available]",0);
}

oList.selectedIndex = 0;
}

function MM_callJS(jsStr) { //v2.0
return eval(jsStr)
}
//-->
</script>
</head>

<body onLoad="MM_callJS('setDynaList(arrDL1)')">
<form name="form1" method="post" action="">
<select name="atype" id="atype" onChange="MM_callJS('setDynaList(arrDL1)')">
<?php
do {
?>
<option value="<?php echo $row_rsType['atypeID']?>"><?php echo $row_rsType['atype']?></option>
<?php
} while ($row_rsType = mysql_fetch_assoc($rsType));
$rows = mysql_num_rows($rsType);
if($rows > 0) {
mysql_data_seek($rsType, 0);
$row_rsType = mysql_fetch_assoc($rsType);
}
?>
</select>
<select name="areg" id="areg">
</select>
</form>
</body>
</html>
<?php
mysql_free_result($rsType);

mysql_free_result($rsAreg);
?>


danke fuer euhre muehe
kupilot ist offline   Mit Zitat antworten


Alt 19.06.2003, 09:50   #2
TP-Moderator
 
Registriert seit: Nov 2002
Ort: Hamburg
DracheTe ist auf einem guten Weg
kann man sich deins irgendwo "auf dem server" ansehen.

php und mysql haben in erster linie wenig damit zu tun (auch wenn du es benötigst), da die eigentlich funktion des wechsels der liste durch javascript gemacht wird.

das bedeutet, daß du deine zweite liste komplett (!!) in javascript in variablen haben musst. diese werden dann natürlich mit php und mysql generiert.


grüsse

daniel
DracheTe ist offline   Mit Zitat antworten
Alt 22.06.2003, 19:57   #3
TP-Member
 
Registriert seit: Apr 2002
Ort: kuwait
kupilot macht alles soweit korrekt
Hallo

Ich hab ein script in www.zend.com gefunden , das so etwas macht allerdings mit hardcodierten arrays , nun moechte ich diesen array von ein database ermittlen.

Hier is der database query erstellet von DWMX:

PHP-Code:
mysql_select_db($database_connLogbook$connLogbook);
$query_rsType "SELECT * FROM atype ORDER BY atype ASC";
$rsType mysql_query($query_rsType$connLogbook) or die(mysql_error());
$row_rsType mysql_fetch_assoc($rsType);
$totalRows_rsType mysql_num_rows($rsType);
mysql_select_db($database_connLogbook$connLogbook);
$query_rsReg "SELECT * FROM areg, atype WHERE areg.atypeID = atype.atypeID ORDER BY areg.areg ASC";
$rsReg mysql_query($query_rsReg$connLogbook) or die(mysql_error());
$row_rsReg mysql_fetch_assoc($rsReg);
$totalRows_rsReg mysql_num_rows($rsReg); 
Hier ist wie ich den array von database ermittle:
PHP-Code:
$atype mysql_fetch_array($rsType);
$areg mysql_fetch_array($rsReg); 
Nun moechte ich anstatt diesen hardcodierten arrays , den arrays von der database einsetzen:

PHP-Code:
$Akey_ID = array("1","2","3","4","5");
$Acat = array("Fruit","Fruit","Fruit","Car","Rodent");
$Asubcat = array("Apples""Bananas""Oranges""Rolls Royce""Gerbil");
$num_in_array 5;
$Adistinct_cats = array("Fruit","Car","Rodent");
$max_items 3
und hier noch den gesamten script , das prima mit den hardcodierten arrays funktioniert:

PHP-Code:
<?php require_once('Connections/connLogbook.php'); ?>
<?php
mysql_select_db
($database_connLogbook$connLogbook);
$query_rsType "SELECT * FROM atype ORDER BY atype ASC";
$rsType mysql_query($query_rsType$connLogbook) or die(mysql_error());
$row_rsType mysql_fetch_assoc($rsType);
$totalRows_rsType mysql_num_rows($rsType);
$atype mysql_fetch_array($rsType);

mysql_select_db($database_connLogbook$connLogbook);
$query_rsReg "SELECT * FROM areg, atype WHERE areg.atypeID = atype.atypeID ORDER BY areg.areg ASC";
$rsReg mysql_query($query_rsReg$connLogbook) or die(mysql_error());
$row_rsReg mysql_fetch_assoc($rsReg);
$totalRows_rsReg mysql_num_rows($rsReg);
$areg mysql_fetch_array($rsReg);


### this neat javascript function from Leon Atkinson updates the second dropdown box
### (subcategory) depending on what is selected in the first (category).
### this function obviously needs to be contained in a form.
###
### array_key_ID is an array of the unique identifiers of the subcategory
### array_cat is the array of categories
### array_subcat is the array of the subcategories
### num_in_array is the total number of items in the array
### distinct_cats is the number of unique items in the category field
### MaxItems is the maximum number of items that can occur in the subcategory dropdown box
###
### Works in IE 4+ and Mozilla 0.9.9+
### Not currently working in Opera (6.02)

function dynamicboxes ($array_key_ID$array_cat$array_subcat$num_in_array$distinct_cats$MaxItems ){

    print 
"<SCRIPT Language=\"JavaScript\">\n";
    print 
"function UpdateSubCat()\n";
    print 
"{\n";
    print 
"\tvar SubCat = document.choose_category.subcat.options.length;\n";
    print 
"\twhile(SubCat > 0)\n";
    print 
"\t{\n";
    print 
"\t\tSubCat--;\n";
    print 
"\t\tdocument.choose_category.subcat.options[SubCat].text = '';\n";
    print 
"\t\tdocument.choose_category.subcat.options[SubCat].value = '';\n";
    print 
"\t}\n\n";
    print 
"\tdocument.choose_category.subcat.options[0].selected = true;\n\n";
    print 
"\tvar CatSelected = 0;\n";
    print 
"\twhile(document.choose_category.cat.options[CatSelected].selected==false) CatSelected++;\n\n";

    
$StoreCat "";
    
$SubCatCount 0;
    
$RowCount 0;

    while(
$RowCount $num_in_array)
        {
        
$item_key_ID $array_key_ID[$RowCount];
        
$item_Cat $array_cat[$RowCount];
        
$item_SubCat $array_subcat[$RowCount];

        if(
$StoreCat != $item_Cat)
            {
            if(
$StoreCat != "")
                {
                print 
"\t}\n";
                }

            print 
"\tif(document.choose_category.cat.options[CatSelected].value == '$item_Cat')\n";
            print 
"\t{\n";
            print 
"\t\tdocument.choose_category.subcat.options[0].value = 0;\n";
            print 
"\t\tdocument.choose_category.subcat.options[0].text = 'Choose a subcategory';\n\n";

            
$StoreCat $item_Cat;
            
$SubCatCount=1;
            }

        print 
"\t\tdocument.choose_category.subcat.options[$SubCatCount].value = '$item_key_ID';\n";
        print 
"\t\tdocument.choose_category.subcat.options[$SubCatCount].text = '$item_SubCat';\n\n";
        
$SubCatCount++;
        
$RowCount++;
        }

    print 
"\t}\n";
    print 
"}\n";
    print 
"</SCRIPT>\n\n";
    print 
"<SELECT NAME=cat onChange=\"UpdateSubCat();\">\n";
    print 
"<OPTION VALUE=0>Choose category";
    
$RowCount 0;
    while(
$RowCount count($distinct_cats))
        {
        print 
"<OPTION VALUE=\"";
        print 
$distinct_cats[$RowCount];
        print 
"\">";
        print 
$distinct_cats[$RowCount];
        print 
"\n";
        
$RowCount++;
        }

    print 
"</SELECT>\n";

    print 
"<SELECT NAME=subcat >\n";
    
$RowCount 0;
    while(
$RowCount <= $MaxItems)
        {
        print 
"<OPTION VALUE=$RowCount>";
        print 
"Subcategory\n";
        
$RowCount++;
        }
    print 
"</SELECT>";
    print 
"<SCRIPT Language=\"JavaScript\">UpdateSubCat();</SCRIPT>\n";

    }
$Akey_ID = array("1","2","3","4","5");
$Acat = array("Fruit","Fruit","Fruit","Car","Rodent");
$Asubcat = array("Apples""Bananas""Oranges""Rolls Royce""Gerbil");
$num_in_array 5;
$Adistinct_cats = array("Fruit","Car","Rodent");
$max_items 3;

print
"<HTML>";

#### Collect the submitted values, then print them:
if (count($HTTP_POST_VARS)) {
    while (list(
$key$value) = each ($HTTP_POST_VARS)) {
        
$arr_request[$key] = $value;
        }
    }
if (
$arr_request[cat]){print $arr_request[cat]." - ".$arr_request[subcat];}


#### Main Form

print "<FORM NAME=choose_category ACTION=$PHP_SELF METHOD=POST>";

dynamicboxes($Akey_ID$Acat$Asubcat$num_in_array$Adistinct_cats$max_items );

print 
"<BR><BR><INPUT TYPE=\"submit\"><BR>\n";
print 
"</FORM>";
print
"</HTML>";


mysql_free_result($rsType);

mysql_free_result($rsReg);
?>
Danke fuer eure hilfe.




Geändert von kupilot (23.06.2003 um 00:37 Uhr).
kupilot ist offline   Mit Zitat antworten
Antwort

  Aktuelles Thema
  TP Hilfe Forum > Web-Editoren & Coding > Traum-Dynamik
dependant dropdown lists dependant dropdown lists
« Formular mit IP Speicherung | umleitung deutsch/engisch »

Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
 
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Thema bewerten
Thema bewerten:

Forumregeln
Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are an
Gehe zu


Alle Zeitangaben in WEZ +2. Es ist jetzt 15:52 Uhr.

Powered by: vBulletin Version 3.7 (Deutsch)
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd. / Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.
Traum-Projekt.com | Suchen | Archiv | Impressum | Kontakt | | | Nach oben |



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67