i have 3 drop dropdown box which is used for searching my database. Either one of them can be selected to perform the search but if none of them is selected it will give an error. Well in reference to this i want the sql query to be based on the values selected by the users. A user might select value from one dropdown box and leave the others or a user can also select values from all three dropdown box. So in this case the query parameters for my query should change accordingly. How is it done in PHP? Infact i tried doing it but i was not successful. Please refer to the code below:[PHP] <?php
$today=date('Y-m-d', mktime());
$q1=$_SESSION['c1'];
$q2=$_SESSION['c2'];
$q3=$_SESSION['c3'];
if(!$q1=="" || $q2=="" || $q3=="") {
$qry = "and tblTenderinfo.c lass='$q1'";
}
elseif(!$q1=="" || !$q2=="" || $q3==""){
$qry = "and tblTenderinfo.c lass='$q1' and tbltenderinfo.c ategory='$q2'";
}
elseif(!$q1=="" || $q2=="" || !$q3==""){
$qry = "and tblTenderinfo.c lass='$q1' and tblclient.categ ory='$q3'";
}
elseif($q1=="" || !$q2=="" || $q3=="") {
$qry = "and tbltenderinfo.c ategory='$q2'";
}
elseif($q1=="" || $q2=="" || !$q3=="") {
$qry = "and tblclient.categ ory='$q3'";
}
/*$qry = "and tblTenderinfo.c lass='$q1' and tbltenderinfo.c ategory='$q2' and tblclient.categ ory='$q3'";*/
?>
<h3>Tender Information for Class <?php echo $q1; ?> Contractors</h3>
<?php
$q = "SELECT tblTenderinfo.t enderId, tblTenderinfo.t enderDesc, tblTenderinfo.c lient,
tblTenderinfo.s ubmdate,tblclie nt.clientagency from tblTenderinfo inner join tblclient
on tblTenderinfo.c lient=tblclient .clientid where tblTenderinfo.s ubmdate>='".$to day."' $qry ORDER BY tblTenderinfo.s ubmdate ASC";[/PHP]
$today=date('Y-m-d', mktime());
$q1=$_SESSION['c1'];
$q2=$_SESSION['c2'];
$q3=$_SESSION['c3'];
if(!$q1=="" || $q2=="" || $q3=="") {
$qry = "and tblTenderinfo.c lass='$q1'";
}
elseif(!$q1=="" || !$q2=="" || $q3==""){
$qry = "and tblTenderinfo.c lass='$q1' and tbltenderinfo.c ategory='$q2'";
}
elseif(!$q1=="" || $q2=="" || !$q3==""){
$qry = "and tblTenderinfo.c lass='$q1' and tblclient.categ ory='$q3'";
}
elseif($q1=="" || !$q2=="" || $q3=="") {
$qry = "and tbltenderinfo.c ategory='$q2'";
}
elseif($q1=="" || $q2=="" || !$q3=="") {
$qry = "and tblclient.categ ory='$q3'";
}
/*$qry = "and tblTenderinfo.c lass='$q1' and tbltenderinfo.c ategory='$q2' and tblclient.categ ory='$q3'";*/
?>
<h3>Tender Information for Class <?php echo $q1; ?> Contractors</h3>
<?php
$q = "SELECT tblTenderinfo.t enderId, tblTenderinfo.t enderDesc, tblTenderinfo.c lient,
tblTenderinfo.s ubmdate,tblclie nt.clientagency from tblTenderinfo inner join tblclient
on tblTenderinfo.c lient=tblclient .clientid where tblTenderinfo.s ubmdate>='".$to day."' $qry ORDER BY tblTenderinfo.s ubmdate ASC";[/PHP]
Comment