SitePoint Sponsor |
|
User Tag List
Results 1 to 2 of 2
-
Jul 3, 2007, 19:32 #1
- Join Date
- May 2006
- Posts
- 87
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Displaying MySQL results with Drop Down Menus
Hello from Palo Alto, California.
Please, I'm stuck on something basic. I have a MySQL table with four records. Each record has two fields, gender and weight. Here's the data:
Mary: female, 150 pounds
Susan: female, 140 pounds
Jack: male, 140 pounds
Bob: male, 150 pounds
I want to code a web page that has two drop down menus -- one for gender, and one for weight -- and a "search" button. It produce a list of names that fit the entered criteria. For example, if "female" and "140" are entered, the result should be a one-name list of "Susan." The HTML part of the code would, I think, be something like the following, but I don't know what PHP code to wrap around it:
<FORM>
Find a
<select name="gender" size="1">
<option value> </option>
<option value="male">male</option>
<option value="female">female</option>
</select>
with a weight of
<select name="weight" size="1">
<option value> </option>
<option value="140">140</option>
<option value="150">150</option>
</select>
<INPUT TYPE="submit" value="Search"></FORM>
Please, any suggestions? Thank you!
-
Jul 3, 2007, 19:47 #2
- Join Date
- Apr 2005
- Posts
- 54
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
This is horrible off-the-top-of-my-head code, but if youve done database requests before, you'll get the point.
if(isset($_POST['acres'])) { //if form was submitted
$gender = $_POST['acres']; //set variables for "acres" dropdown
$weight = $_POST['state']; //set variable for "state" dropdown
$result = "SELECT * FROM TABLENAME_HERE WHERE gender = $gender & weight = $weight"; //select only where those two fields match up
while (mysql_fetch_array(result)) { //will only loop through rows in which both of those feilds match.
name = row(name);
weight = row(weight);
gender = row(gender);
echo $name $gender $weight;
}
Bookmarks