Combobox met php

Status
Niet open voor verdere reacties.

Ruben1981

Gebruiker
Lid geworden
6 dec 2003
Berichten
208
geachte,

ik ben niet bepaald bekend met php maar ik wil namelijk het volgende realiseren. Op een pagina moeten 3 combobox'en komen te staan

de eerste box bevat de Leveranciers
bijvoorbeeld; HP, Canon, Lexmark,...

de tweede box bevat het type printer van de bovengenoemde leveranciers

bijvoorbeeld: HP PSC 2110, HP LJ-2550, Canon IP5000,....

en de derde box bevat het type cartridge voor de in de 2de box aangegeven printer.

Nu moet het zo zijn, dat wanneer je combobox 1 een merk geselecteerd hebt, dat automatisch alle printer van dat merk in dit rijtje voorkomen (in combobox2), dus geen canon printers als je hp hebt gekopen.

en dit geldt eveneens voor de 3de box.

Is dit mogelijk icm mysql? Beschikt iemand over zo'n script of weet iemand waar ik zo'n script kan downloaden

b.v.d.
 
Je moet daarvoor even aan jan koehoorn op phphulp.nl vragen, die heeft zo'n script op z'n site staan
 
Ik had het script al gevonden daar, maar er klopt het een en ander volgens mij niet, want bij mij zie je in de 2de combobox toch alle merken incl. type terwijl dit enkel en alleen het type moet zijn van het merk dat in de eerste combo box is geselecteerd

Maar heb geen idee waar die fout precies zit.

PHP:
<?php
// include de database connectie
include("config.php");
include("db.php");
?>
<html>
<head>
<title>de dropdown functie></title>
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.merk.options[form.merk.options.selectedIndex].value;
self.location='dropdown.php?auto_merk=' + val ;
}

</script>
</head>
<body>
<?php
///////// pak de data uit de db//////////
$quer2=DoQuery("SELECT DISTINCT merk,merk_id FROM auto_merk order by merk");
/////////////einde////////////

/////// als in de eerste dropdown niks geselect is dan laat de 2de drop alles zien/////
if(isset($poule) and strlen($poule) > 0){
$quer=DoQuery("SELECT DISTINCT type FROM auto_type where merk_id=$auto_merk order by merk_id");
}else{$quer=DoQuery("SELECT DISTINCT type FROM auto_type order by merk_id"); }
////////// einde ///////////////////////////

echo "<form method=post name=f1 action=''>";
//////////        eerste drop /////////
echo "<select name='merk' onchange=\"reload(this.form)\"><option value=''>Selecteer uw automerk</option>";
while($line = mysql_fetch_array($quer2))
{
    if($line['merk_id']==@$auto_merk)
    {echo "<option selected value='$line[merk_id]'>$line[merk]</option>"."<BR>";
    }else{
        echo  "<option value='$line[merk_id]'>$line[merk]</option>";
        }
}
echo "</select>";
//////////////////  einde ///////////

//////////        2de drop /////////
echo "<select name='type'><option value=''>Selecteer type auto</option>";
while($line2 = mysql_fetch_array($quer)) {
echo  "<option value='$line2[type_id]'>$line2[type]</option>";
}
echo "</select>";
//////////////////  einde ///////////

echo "</form>";
echo "<input type='text' name='test' value=''>";

?>
</body>
</html>

de tabellen

PHP:
CREATE TABLE auto_merk (
auto_merk_id int(2) NOT NULL auto_increment,
auto_merk varchar(25) NOT NULL default '',
PRIMARY KEY (auto_merk_id)
) TYPE=MyISAM; 

-- 
-- Gegevens worden uitgevoerd voor tabel `auto_merk`
-- 

INSERT INTO `auto_merk` VALUES (1, 'Alfa Romeo');
INSERT INTO `auto_merk` VALUES (2, 'Audi');
INSERT INTO `auto_merk` VALUES (3, 'BMW');
INSERT INTO `auto_merk` VALUES (4, 'Citroën');
INSERT INTO `auto_merk` VALUES (5, 'Fiat');
INSERT INTO `auto_merk` VALUES (6, 'Ford');
INSERT INTO `auto_merk` VALUES (7, 'Honda');
INSERT INTO `auto_merk` VALUES (8, 'Lancia');
INSERT INTO `auto_merk` VALUES (9, 'Maserati');
INSERT INTO `auto_merk` VALUES (10, 'Mazda');
INSERT INTO `auto_merk` VALUES (11, 'Mercedes');
INSERT INTO `auto_merk` VALUES (12, 'Nissan');
INSERT INTO `auto_merk` VALUES (13, 'Opel');
INSERT INTO `auto_merk` VALUES (14, 'Peugeot');
INSERT INTO `auto_merk` VALUES (15, 'Porsche');
INSERT INTO `auto_merk` VALUES (16, 'Renault');
INSERT INTO `auto_merk` VALUES (17, 'Rover');
INSERT INTO `auto_merk` VALUES (18, 'Seat');
INSERT INTO `auto_merk` VALUES (19, 'Skoda');
INSERT INTO `auto_merk` VALUES (20, 'Volkswagen');




CREATE TABLE auto_type (
type_id int(2) NOT NULL auto_increment,
merk_id int(2) NOT NULL default '0',
type varchar(25) NOT NULL default '',
PRIMARY KEY (type_id) ) TYPE=MyISAM; 

INSERT INTO auto_type VALUES (1, 1, 'Alfa Romeo 156');
INSERT INTO auto_type VALUES (2, 1, 'Alfa Romeo GTV');
INSERT INTO auto_type VALUES (3, 1, 'Alfa Romeo Spider');
INSERT INTO auto_type VALUES (4, 2, 'Audi A2');
INSERT INTO auto_type VALUES (5, 2, 'Audi A3');
INSERT INTO auto_type VALUES (6, 2, 'Audi A4');
INSERT INTO auto_type VALUES (7, 2, 'Audi A6');
INSERT INTO auto_type VALUES (8, 2, 'Audi A8');
INSERT INTO auto_type VALUES (9, 2, 'Audi TT');
INSERT INTO auto_type VALUES (10, 3, 'BMW 3 Serie');
INSERT INTO auto_type VALUES (11, 3, 'BMW 5 Serie');
INSERT INTO auto_type VALUES (12, 3, 'BMW 7 Serie');
INSERT INTO auto_type VALUES (13, 3, 'BMW M3');
INSERT INTO auto_type VALUES (14, 3, 'BMW M5');
INSERT INTO auto_type VALUES (15, 3, 'BMW X5');
INSERT INTO auto_type VALUES (16, 4, 'Citroën C5');
INSERT INTO auto_type VALUES (17, 5, 'Fiat Multipla');
INSERT INTO auto_type VALUES (18, 5, 'Fiat Punt');
INSERT INTO auto_type VALUES (19, 6, 'Ford Fiesta / Fusion');
INSERT INTO auto_type VALUES (20, 6, 'Ford Focus');
INSERT INTO auto_type VALUES (21, 6, 'Ford Foucs C-MAX');
INSERT INTO auto_type VALUES (22, 6, 'Ford Galaxy');
INSERT INTO auto_type VALUES (23, 6, 'Ford Mondeo');
INSERT INTO auto_type VALUES (24, 7, 'Honda Accord');
INSERT INTO auto_type VALUES (25, 7, 'Honda Civic');
INSERT INTO auto_type VALUES (26, 7, 'Honda CRV');
INSERT INTO auto_type VALUES (27, 7, 'Honda HRV');
INSERT INTO auto_type VALUES (28, 7, 'Honda Prelude');
INSERT INTO auto_type VALUES (29, 7, 'Honda Shuttle');
INSERT INTO auto_type VALUES (30, 8, 'Lancia Kappa');
INSERT INTO auto_type VALUES (31, 8, 'Lancia Y');
INSERT INTO auto_type VALUES (32, 9, 'Maserati All Models');
INSERT INTO auto_type VALUES (33, 10, 'Mazda 323');
INSERT INTO auto_type VALUES (34, 10, 'Mazda MPV');
INSERT INTO auto_type VALUES (35, 10, 'Mazda MX5');
INSERT INTO auto_type VALUES (36, 10, 'Mazda Premacy');
INSERT INTO auto_type VALUES (37, 10, 'Mazda Xedos 9');
INSERT INTO auto_type VALUES (38, 11, 'Mercedes C-class');
INSERT INTO auto_type VALUES (39, 11, 'Mercedes CL');
INSERT INTO auto_type VALUES (40, 11, 'Mercedes CLK');
INSERT INTO auto_type VALUES (41, 11, 'Mercedes E-class');
INSERT INTO auto_type VALUES (42, 11, 'Mercedes G-class');
INSERT INTO auto_type VALUES (43, 11, 'Mercedes M-class');
INSERT INTO auto_type VALUES (44, 11, 'Mercedes S-class');
INSERT INTO auto_type VALUES (45, 11, 'Mercedes SL-clas');
INSERT INTO auto_type VALUES (46, 12, 'Nissan All Models');
INSERT INTO auto_type VALUES (47, 13, 'Opel Combo');
INSERT INTO auto_type VALUES (48, 13, 'Opel Vivario');
INSERT INTO auto_type VALUES (49, 13, 'Opel/Vauxhall Astra');
INSERT INTO auto_type VALUES (50, 13, 'Opel/Vauxhall Corsa');
INSERT INTO auto_type VALUES (51, 13, 'Opel/Vauxhall Omega');
INSERT INTO auto_type VALUES (52, 13, 'Opel/Vauxhall Vectra');
INSERT INTO auto_type VALUES (53, 13, 'Opel/Vauxhall Zafira');
INSERT INTO auto_type VALUES (54, 14, 'Peugeot All Models');
INSERT INTO auto_type VALUES (55, 15, 'Porsche All Models');
INSERT INTO auto_type VALUES (56, 16, 'Renault All Models');
INSERT INTO auto_type VALUES (57, 17, 'Rover All Models');
INSERT INTO auto_type VALUES (58, 18, 'Seat Ibiza');
INSERT INTO auto_type VALUES (59, 18, 'Seat Leon');
INSERT INTO auto_type VALUES (60, 18, 'Seat Alhambra');
INSERT INTO auto_type VALUES (61, 18, 'Seat Toleda');
INSERT INTO auto_type VALUES (62, 19, 'Skoda Fabia');
INSERT INTO auto_type VALUES (63, 19, 'Skoda Superb');
INSERT INTO auto_type VALUES (64, 19, 'Skoda Oktavia');
INSERT INTO auto_type VALUES (65, 20, 'Volkswagen T4');
INSERT INTO auto_type VALUES (66, 20, 'Volkswagen Touareg');
INSERT INTO auto_type VALUES (67, 20, 'Volkswagen Touran');
INSERT INTO auto_type VALUES (68, 20, 'Volkswagen Bora');
INSERT INTO auto_type VALUES (69, 20, 'Volkswagen Golf');
INSERT INTO auto_type VALUES (70, 20, 'Volkswagen Lupo');
INSERT INTO auto_type VALUES (71, 20, 'Volkswagen Passat');
INSERT INTO auto_type VALUES (72, 20, 'Volkswagen Polo');
INSERT INTO auto_type VALUES (73, 20, 'Volkswagen Sharan');
INSERT INTO auto_type VALUES (74, 20, 'Volkswagen T5 Multivan');
 
Hoe kom je aan $poule?

Als dat via de url of via het form binnen komt moet je

in het geval van PHP versie lager dan 4.01:
in het geval van posting(form): $HTTP_POST_VARS['poule']
in het geval van url(get): $HTTP_GET_VARS['poule']

en in het geval van php versie hoger dan 4.01:
in het geval van post: $_POST['poule']
en in het geval van get: $_GET['poule']

gebruiken
 
Wat 'n bagger script. Zowel de javascript als de PHP.

Als je iemand iets aanraadt, moet je er vrij zeker van zijn dat het werkt.

Ruben, heb je enig idee wat het script dat je nu hebt eigenlijk doet ?
 
Even voor de goede orde, ik ben niet bepaald bekend met php, ben net pas begonnen met dit spul.

Ik heb op mijn pc PHP 4.4.1 geinstalleerd.

En wat het doet het script, ik heb geen idee eerlijk gezegd, maar ik kan je wel vertellen dat het script niets speciaals doet, het leest 2 tabellen uit mijn database en zet deze in een combobox, maar dat is dan ook alles. En verder, tja wat moet ik zeggen.


groetjes

Ruben
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan