Hey there. Glad to find a site like this. I just started playing with php and mySQL tonight for the first time, and I've come across a snag.
Here's the setup:
I've created a database, and I want the user to select the criteria to search on. They can pick "A","B", or "C" from the pulldown menu, and I have that pulled into the "Select" statement in the page it calls. Works like a champ.
However, I'd also like for them to be able to choose a "Show all" for that category, where "A", "B", and "C" would show up. How can I do this?
Working example page: http://www.cccmemphis.org/catsearch.php
You can select "DSH" or "DMH", but selecting "Show all breeds" returns nothing. I currently have the value of "Show all breeds" set to null.
The php code I have now:
The search page
php Code:
Original
- php Code |
|
|
|
<form method="post" action="catsearchpage.php">
Gender:<select name="catgender" size="1">
<option value=Female>Female</select><br>
Breed:<select name="catbreed" size="1">
<option value="">Show all breeds!
<option value="Domestic Short Hair">DSH
<option value="Domestic Medium Hair">DMH
</option>
</select><br>
Fixed?:<select name="catfixed" size="1">
<option value="Yes">Yes</select><br>
<input type="Submit" name="submit" value="Search">
</form>
and the catsearchpage.php that the form calls:
php Code:
Original
- php Code |
|
|
|
<?php
$dbh=
mysql_connect ("localhost",
"cccmemph_jimlord",
"fsoop") or
die ('I cannot connect to the database.');
WHERE gender = '$catgender'
AND breed = '$catbreed'
AND fixed = '$catfixed'
AND status = 'Adoptable'");
if (!$result) {
}
// process the row...
echo("<tr><td valign=top>Name: " .
$row["name"] .
"</br>");
echo("Gender: " .
$row["gender"] .
"</br>");
echo("Coat: " .
$row["coat"] .
"</br>");
echo("Breed: " .
$row["breed"] .
"</br>");
echo("Disposition: " .
$row["disposition"] .
"</br>");
echo("Birthdate: " .
$row["birthdate"] .
"</br>");
echo("Status: " .
$row["status"] .
"</br>");
echo("Fixed?: " .
$row["fixed"] .
"</br>");
echo("Description: " .
$row["description"] .
"</td><td valign=top>");
echo("<img width=250 src=" .
$row["photo"] .
"></td><tr>");
}
?>
Looks like I'm going to like this stuff, and next I'll be building the admin for someone else to do the updating of content. I run a site that someone else has designed using ASP, so I'm a bit familiar with the concepts here, but not coding. Any help is appreciated.