
May 25th, 2003, 02:20 PM
|
|
|
|
Join Date: Apr 2007
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
phylum/order/class/family/genus
1. How should my query be written to do the following. I have a form that posts to the page with the query...the form has five fields
Phylum
Clase
Orden
Familia
Genero
What I want is that if the user only fills in the phylum field, only the phylum result will be shown. If the user fills in the phylum and class field, again, only those two results are shown. However if the user fills in let's say the genero field than that field and all the fields above it are shown. In other words, I need the query to display the chosen field and all those above it even if the fields above the chose field have not been filled in. Am I explaining that clearly?
php Code:
Original
- php Code |
|
|
|
<?php require_once('../Connections/connfauna.php'); ?> <?php $query_rsadd = "SELECT * FROM fauna"; if(isset($_GET['phylum'])){ $varphylum = $_GET['phylum']; $query_rsadd .=" WHERE phylum LIKE '%$varphylum%'"; if(isset($_GET['clase'])){ $varclass = $_GET['clase']; $query_rsadd .=" AND clase LIKE '%$varclase%'"; if(isset($_GET['orden'])){ $varord = $_GET['orden']; $query_rsadd .=" AND orden LIKE '%$varord%'"; if(isset($_GET['familia'])){ $varfam = $_GET['familia']; $query_rsadd .=" AND familia LIKE '%$varfam%'"; if(isset($_GET['genero'])){ $vargen = $_GET['genero']; $query_rsadd .=" AND genero LIKE '%$vargen%'"; } } } } } ?> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <p><?php echo $row_rsadd['phylum']; ?> </p> <p><?php echo $row_rsadd['clase']; ?></p> <p> <?php echo $row_rsadd['orden']; ?> </p> <p><?php echo $row_rsadd['familia']; ?> </p> <p><?php echo $row_rsadd['genero']; ?> </p> <p><?php echo $row_rsadd['especie']; ?> </p> </body> </html>
Any ideas would be greatly appreciated
|