473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Having trouble or possibly i am just TOO stupid to understand

keyvanrahmadi
I have created a form which is as Follow:

[HTML]

<form action="fleet-of-car.php" method="post">
<br />SELECT A FORM TO SEE :
<select name="FORM">
<option value="ALL CARS"/>All Cars
<Option Value="CARS BY MANUFACTURER"/>CARS BY MANUFACTURER
<Option Value="CARS BY FUEL TYPE"/>CARS BY FUEL TYPE
</select>
<br />
<input type="submit" value="Show INFO" />
</form>
</select>

[/HTML]

Now what i am trying to achieve is as follow:

1: By submitting the first option in this case All cars, the form should connect to DB and run the query, which if i am not wrong is as follow:

[PHP]

<?php

//make a connection

mysql_connect("server", "user", "password");
mysql_select_db ('db', $connection);

//Run the Sql
$results = mysql_query("SELECT * FROM car
");

?>

[/PHP]

The question i have is, what happens if the user selcets option 2 or even 3? The query will be different since it will read from different Mysql table to get the result, but what is the script required for this type query.

I though by using IF(isset), i might get away with it but i am not too familiar with it and i have no idea even where to start, WHILE statement should do it but i am just getting more confused.

Any help would be great guys, and thx well in advance

keyvan
Feb 16 '07 #1
1 1170
Atli
5,058 Expert 4TB
Hi.

If Im understanding you correctly, you would need to do something like this.

[PHP]
<?php

$option = $_POST['Name'];

// Find the selected option
if($option == "whatever")
{
$query = "SELECT * FROM table1";
}
else if($option == "somethingelse")
{
$query = "SELECT * FROM table2";
}
// ....
else
{
$query = "";
}

// Run the query
if($query != "")
{
$DB = mysql_connect("h", "u", "p") or die("omg it didnt work!");
mysql_select_db("d", $DB) or die("aaah! so close!");

$result = mysql_query($query) or die("<p>MySQL Error: <br />". mysql_error() ."</p>");

// Do something with results
}
else
{
// Error msg if the option is invalid
echo "Invalid option";
}

?>
[/php]

Hope this helps.
Feb 16 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Charles Krug | last post by:
List: I'm trying to use the example files from Programming Python, 2nd Ed. I've copied them into c:\Python24\Examples\PP2E. Launching any of the examples programs by themselves seems to work...
6
by: Jeremy Cowles | last post by:
Hi all, Disclaimer: This app is actually written in a different language, but I have much respect for this group & wanted to get your input so please ignore any minor syntactical errors. I...
14
by: Gregory L. Hansen | last post by:
I can't seem to make a queue of objects, using the STL queue. I'm trying to make a little event manager, and I just want someplace to store events. The method definitions for EventManager have...
4
by: 21novembre | last post by:
Hi all, I got a quite strange problem when I tried to setup a database backup shell. I put it this way: "bin/mysqldump --opt --user=xxx --password=xxx DB > DB.bak" However, error 1045 came to...
5
by: Krumble Bunk | last post by:
Hello! First things first (but not necessarily in that order), this is a really great group, and has helped me understand more and more C everytime I read the postings, so thanks for a great...
16
by: John Rivers | last post by:
http://www.15seconds.com/Issue/030812.htm?voteresult=1 poor guy worked his heart out, just to make a page control and then they published it ha ha ha ha ha to "help" others
18
by: fishwick | last post by:
I haven't really done any css in quite a while, and am banging my head against the wall trying get the rudimentary layout together of a church website home page to display correctly - I don't want...
2
by: Stu | last post by:
Hi guys, I've been having trouble getting the clock function to work portably, please could I get some thoughts? <Possibly OT comments> It works fine on my laptop (under WinXP) and on my...
39
by: rembremading | last post by:
Hi all! The following piece of code has (for me) completely unexpected behaviour. (I compile it with gcc-Version 4.0.3) Something goes wrong with the integer to float conversion. Maybe somebody...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.