473,491 Members | 2,221 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dropdownbox read from Mysql to PHP

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..
Jul 17 '05 #1
6 2004
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
Jul 17 '05 #2
> 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)
Jul 17 '05 #3
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$"";
}

?>

Jul 17 '05 #4
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
Jul 17 '05 #5
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.

Jul 17 '05 #6
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..

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2640
by: DD | last post by:
I have a mainform with a subform. > The main form has a dropdown box "chooseMonth", in the afterupdate event > i requery the subform so all records with the same date are viewed. > Now i only want...
3
338
by: DD | last post by:
I have a mainform with a subform. > The main form has a dropdown box "chooseMonth", in the afterupdate event > i requery the subform so all records with the same date are viewed. > Now i only want...
0
949
by: Sunil Sabir | last post by:
Dear All, I have a web form which has a link and a drop down box. when I press a link a pop up window opens. This window has a lot of TEXTBOXES and a Save button. When I fill the TextBoxes and...
2
1731
by: Lars Netzel | last post by:
Hi I'm having a DropDown box with 2 items... one with Value 1 and one with Value 2. If I load the page and it has Value 1 selected from page_load() and then select Value 2 on the form.. .and...
0
7115
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7154
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6858
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7360
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4578
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3086
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1392
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.