> I have a MySqlBase with a tabel named CARS and with 3 fields;
CarsType, CarsModel, CarsInfo.
Now I want to generate 2 dropdownboxes in PHP read from CARS.
First I will "load" CarsType into an dropdownbox, and then I make a
choice, exampel FORD, now the next dropdownbox (CarsModel) will show
Escort, Sierra and so...
Finally I will make a "actionbutton" named showinfo and when I click
it will show CarsInfo.
Can anybody help me ?
Best regards and thanks
The firts php file (carstype.php for example) should look like this. It will
list the types of cars in the db into a dropdownbox:
================================================== ==========================
======
<?php
require "cars.inc.php";
$cars_db = cars_connecte_db();
$str_requete = "SELECT CarsType FROM cars ORDER BY CarsType ASC";
$result_articles = mysql_query ($str_requete,$cars_db) or
cars_mysql_die();
print ('<form method=post action=carsmodel.php><select name=CarsType>');
while ($articleDb =mysql_fetch_object($result_articles))
{
print("
<option
value='$articleDb->CarsType'>$articleDb->CarsType</option>
");
}
print ('</select>
<input type=submit name=send value=Send>
</form>');
?>
================================================== ==========================
======
The second file (carsmodel.php for example) should look like this. It will
list the models of the cartype you have selected in carstype.php in a
dropbox
================================================== ==========================
=======
<?php
require "cars.inc.php";
$cars_db = cars_connecte_db();
$str_requete = "SELECT CarsModel,CarsType FROM cars WHERE
CarsType='$CarsType' ORDER BY CarsModel ASC";
$result_articles = mysql_query ($str_requete,$cars_db) or
cars_mysql_die();
print ('<form method=post action=carsinfo.php><select name=CarsModel>');
while ($articleDb =mysql_fetch_object($result_articles))
{
print("
<option
value='$articleDb->CarsModel'>$articleDb->CarsModel</option>
");
}
print ('</select>
<input type=submit name=send value=Send>
</form>');
?>
================================================== ====================
The third file with the result should than look like
================================================== ====================
<?php
$db = mysql_connect("localhost","username","password");
mysql_select_db("databasename",$db);
$sql = mysql_query("SELECT CarsModel,CarsType,CarsInfo FROM cars WHERE
CarsModel='$CarsModel'");
$sql_doublecheck = mysql_query("SELECT CarsModel,CarsType FROM contacts
WHERE CarsModel='$CarsModel' AND CarsType='$CarsType'");
$doublecheck = mysql_num_rows($sql_doublecheck);
if($doublecheck == 0){
echo "<strong><font color=red>The info you requested is not
available!</font></strong>";
} elseif ($doublecheck > 0) {
echo "The information of the car "$CarsInfo$"";
}
?>
================================================== ==========================
================
The contents of cars.inc.php
================================================== ==========================
================
<?php
function cars_mysql_die($error = "")
{
if (empty($error))
{
$mysqlError = mysql_error();
if (!empty($mysqlError))
{
echo "SQL server reply: ".$mysqlError;
}
}
else
echo "SQL server reply: ".$error;
echo "<br><a href=\"javascript
:history.go(-1)\">Terug</a>";
exit;
}
function cars_connecte_db()
{
// Server connection parameter
require "cars.conf.php";
$db = mysql_connect($host,$login,$password) or cars_mysql_die();
mysql_select_db($base);
return $db;
}
?>
================================================== ==========================
==================
The contents of cars.conf.php
================================================== ==========================
==================
<?php
// configuration of my database
$host = "localhost";
$login= "username";
$base = "databasename";
$password="password";
?>
================================================== ==========================
==================
--
RotterdamStudents
-------------------------------
Dulce est despirere loco
(Horatius, "Oden" 4,12,28)