473,598 Members | 3,018 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

setting different query parameters from multiple dropdown box

114 New Member
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]
Sep 19 '08 #1
2 1678
Atli
5,058 Recognized Expert Expert
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 New Member
thankyou somuch, it worked.
Sep 19 '08 #3

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

Similar topics

4
3517
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 dropdown list from which he can select, because the parameters are rather long... Does anyone know how to make that dropdown list? TIA
1
3548
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 OleDb.OleDbCommand("zsp_web_WebDocument", cnnSearch) cmdWebDocGroup.CommandType = CommandType.StoredProcedure prmWebDocGroup = cmdWebDocGroup.Parameters.Add("@strParm00",
3
5611
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 was in the Project Properties dialog under the Debugging tab. There's a dropdown box where you can set the start up page. But VS ignores the querystring I add to the page name in this combo box. I know this because the Request.QueryString...
3
1429
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 dataset. in my codebehind, i have in an "If Not Page.IsPostBack" block with statements that populate each of the dropdown lists. there could be up to 10 dropdowns lists used, which means the current way i'm doing it i'd have 10 sets of the same...
0
1580
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. Now, I need to read the results of this query in an event procedure, but I consistently get a run-time error (3061): Too few parameters. Expected 3. The code I'm using to open the query's recordset is as follows: Set dbs=CurrentDb Set...
2
1833
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 this form a query is created (UserQuery) which consequently sets the dates (as entered by the user) for all the other queries. I have made a new form which runs a different query but still relies on the UserQuery to set the dates. currently the...
6
1699
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 suspect that there is a way to insert criteria into a query besides opening it up and typing "and" and "or" on the criteria row of each column. I have a query that shows thousands of records (students in different classes taking different tests)...
5
5295
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 user prompted for them). Based on a Microsoft page (http://support.microsoft.com/kb/287437), I tried the following approach: Private Sub Report_Open(Cancel As Integer) Dim sql As String
0
1280
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... (basically these are certain field names in my query). I also have a command button called “Run query”. Currently, I have designed it so that if I select any of the options in my dropdown list I am able to narrow down my query result. I accomplished this by...
0
7894
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8284
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8392
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8262
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6711
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5847
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3894
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3938
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2410
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.