Dropdownbox read from Mysql to PHP – PHP

  php

Q(Question):

Hi,

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

Thomas J, Denmark.
Not so good at english..hope you understand..

A(Answer):

In article <60**************************@posting.google.com >, thomas j wrote:

Hi,

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.

Here is pseudocode that does what you want, translation to php i leave
to you 😉

In all the cases you have to know all the types to generate the first
selectbox

check if a type was selected:

no: ready.

yes:

get all the models for the selected type and generate 2nd
selectbox

check if a model was selected:

no: ready.

yes:
get info for selected model and type and show this.

http://home.mysth.be/~timvw

A(Answer):

> 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)

A(Answer):

Hi,
Thanks.
It almost working fine;
But I get an:
Parse error: parse error, expecting `’,” or `’;” in carsinfo.php on line 15

(line with elseIf)

Can You help me ?
Thanks.
Thomas J.

================================================== ====================

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$"";
}

?>

A(Answer):

On 7 May 2004 13:28:39 -0700, tj******@ofir.dk (thomas j) wrote:

echo "The information of the car "$CarsInfo$"";

It almost working fine;
But I get an:
Parse error: parse error, expecting `’,” or `’;” in carsinfo.php on line 15

(line with elseIf)

Look at the quotes you have on the line remaining above. This will cause a
parse error.


Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space

A(Answer):

Now, I not getteing an ParseError, but now I can get no CarsInfo, even
there is data in my field CarsInfo. It Allways say "No Information
about the car"
Maybe it is the value/My choice from CarsModel.php that not being
"taking over" to CarsInfo.php.

Thanks
Thomas J.

Andy Hassall <an**@andyh.co.uk> wrote in message news:<5t********************************@4ax.com>. ..

On 7 May 2004 13:28:39 -0700, tj******@ofir.dk (thomas j) wrote:

echo "The information of the car "$CarsInfo$"";

It almost working fine;
But I get an:
Parse error: parse error, expecting `’,” or `’;” in carsinfo.php on line 15

(line with elseIf)

Look at the quotes you have on the line remaining above. This will cause a
parse error.

A(Answer):

You are better off loading all of them into arrays, from there you
will populate Javascript arrays that will be loaded from the client.

It’s faster and more efficient, quick grab and go.

Ha det bra!

Phil

tj******@ofir.dk (thomas j) wrote in message news:<60**************************@posting.google. com>…

Hi,

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

Thomas J, Denmark.
Not so good at english..hope you understand..

LEAVE A COMMENT