473,396 Members | 1,998 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,396 software developers and data experts.

setting different query parameters from multiple dropdown box

114 100+
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.class='$q1'";
}
elseif(!$q1=="" || !$q2=="" || $q3==""){
$qry = "and tblTenderinfo.class='$q1' and tbltenderinfo.category='$q2'";
}
elseif(!$q1=="" || $q2=="" || !$q3==""){
$qry = "and tblTenderinfo.class='$q1' and tblclient.category='$q3'";
}
elseif($q1=="" || !$q2=="" || $q3=="") {
$qry = "and tbltenderinfo.category='$q2'";
}
elseif($q1=="" || $q2=="" || !$q3=="") {
$qry = "and tblclient.category='$q3'";
}

/*$qry = "and tblTenderinfo.class='$q1' and tbltenderinfo.category='$q2' and tblclient.category='$q3'";*/

?>
<h3>Tender Information for Class <?php echo $q1; ?> Contractors</h3>
<?php
$q = "SELECT tblTenderinfo.tenderId, tblTenderinfo.tenderDesc, tblTenderinfo.client,
tblTenderinfo.submdate,tblclient.clientagency from tblTenderinfo inner join tblclient
on tblTenderinfo.client=tblclient.clientid where tblTenderinfo.submdate>='".$today."' $qry ORDER BY tblTenderinfo.submdate ASC";[/PHP]
Sep 19 '08 #1
2 1667
Atli
5,058 Expert 4TB
Hi.

You could use implode to make this easier.

Like:
Expand|Select|Wrap|Line Numbers
  1. // Set up and an array for the implode function
  2. $constraints = array();
  3.  
  4. // Check each input
  5. if(isset($_GET['var1'])) {
  6.   $safe = mysql_real_escape_string($_GET['var1']);
  7.   $constraints[] = "`col1` = '$safe'";
  8. }
  9. if(isset($_GET['var2'])) {
  10.   $safe = mysql_real_escape_string($_GET['var2']);
  11.   $constraints[] = "`col2` = '$safe'";
  12. }
  13. // etc...
  14.  
  15. // Create the WHERE clause using the implode function
  16. $whereString = implode(" AND ", $constraints);
  17.  
  18. // Create the SQL query
  19. $query = "SELECT stuff FROM myTbl WHERE $whereString";
  20.  
  21. // etc..
  22.  
  23.  
  24.  
Sep 19 '08 #2
raaman rai
114 100+
thankyou somuch, it worked.
Sep 19 '08 #3

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

Similar topics

4
by: Theo Jansen | last post by:
Hi, i'm making an application in Access and in the query made, i'd like the user to fill in a parameter when opening the query (in a report). It's much easier for the user if the parameter was a...
1
by: Steven K | last post by:
Hello, I am calling a SQL Server 2K parameter query with the following: Dim spWebDocGroup As OleDb.OleDbDataReader Dim prmWebDocGroup As OleDbParameter Dim cmdWebDocGroup As New...
3
by: Nobody | last post by:
Hi -- I'm developing an ASP.NET application in VS.NET and I want the startup page to read in some parameters from a querystring. But I can't figure out where to set the querystring. I thought it...
3
by: simon | last post by:
hello, i have a form where there are multiple dropdown lists that will all be populated from the same initial data query. i have a vb class defined to make the stored proc call and that returns a...
0
by: Greg Pyle | last post by:
I have created a parameter query (qryAuthors) that reads three parameters from three different fields on a subform (Subform1). Each time the form record changes, the query updates automatically. ...
2
by: StuckProgrammer | last post by:
Hi, I have 10 queries linked together via an incident number. There is a form where the user enters start and end dates to define which incident numbers are used within the queries. On running...
6
by: jim | last post by:
Is anyone able to provide me with a link to useful documentation or just outright explain to me how to set query parameters dynamically? I'm really new to Access and databases in general but I...
5
by: dana1 | last post by:
Hello Experts! Does anyone know if there is a way to set the values of query parameters from VBA for a report's recordsource? (i.e., I want to set the values of the parameters and NOT have the...
0
kcdoell
by: kcdoell | last post by:
Hello: I have a form that I am using to help me display a query that I have built. On that form I have multiple combo boxes that I have called cobMonth, cobYear, cobWorkingRegion, etc......
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.