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

run query with empty form field

hi,

i have the following:

Expand|Select|Wrap|Line Numbers
  1. $T_GROUP = $_POST["T_GROUP"];
  2. $site = $_POST["site"];
  3. ....
  4. $sql="SELECT day, field1, field3, field4, field5 FROM qry_sum WHERE field3 = '".$T_GROUP."' AND field2 LIKE '".$site."' AND day = 'SUNDAY';
  5. $rs=odbc_exec($conn,$sql);
  6. if (!$rs)
  7.   {exit("Error in SQL");}
  8.  
  9. while (odbc_fetch_row($rs))
  10. {
  11.   $SFT=odbc_result($rs, shift);
  12.   $BER=odbc_result($rs, infocount);
  13.   $TTLS=odbc_result($rs2, ttl);
  14.   $TTLGRAND=odbc_result($rs3, ttl_GRAND);    
  15. print "<br>";
  16.  
  17. echo $SFT;
  18.  
  19.  
when there is a value in the "site" form field the query retrieves records related to that site. i would like to know if there is a way the query can retrieve ALL results when the "site" form field is empty?



thanks in advance,
geebee
Jan 15 '09 #1
4 1908
Markus
6,050 Expert 4TB
Sure, you can do that. Just check to see whether your 'site' field is empty (or not set).

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. // ...
  4.  
  5. if ( ! isset ( $_POST['site'] ) || $_POST['site'] == "" )
  6. {
  7.     // Code for all sites goes here
  8. }
  9. else
  10. {
  11.     // Code for specific site goes here
  12. }
  13.  
  14. ?>
  15.  
  16.  
Then, in your SELECT query, simply omit any WHERE clause from the query - that way, when you run the query, it will return every row from the table (ie. all your sites).

Hope this helps,
Markus.
Jan 15 '09 #2
ok.. i now have...

Expand|Select|Wrap|Line Numbers
  1. if ( ! isset ( $_POST['fac'] ) || $_POST['fac'] == "" ) 
  2. ...
  3. $sql="SELECT admitday, shift, SRG_GROUP, sum(infocount) as infocount2, hospitalcode FROM qry_sum WHERE SRG_GROUP = '".$SRG_GROUP."' AND hospitalcode LIKE '".$fac."' AND admitday ='".$count."'";
  4. else
  5. $sql="SELECT admitday, shift, SRG_GROUP, infocount, hospitalcode FROM qry_sum WHERE SRG_GROUP = '".$SRG_GROUP."' AND admitday ='".$count."'";
  6.  
  7. ....
  8. ....
  9. if ( ! isset ( $_POST['fac'] ) || $_POST['fac'] == "" ) 
  10. $BER=odbc_result($rs, infocount2);
  11. else
  12. $BER=odbc_result($rs, infocount);
  13.  
  14.  
but i am getting an error...
Jan 15 '09 #3
Markus
6,050 Expert 4TB
@geraldjr30
It would help to know the error.
Jan 15 '09 #4
"Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] You tried to execute a query that does not include the specified expression 'admitday' as part of an aggregate function., SQL state 37000 in SQLExecDirect "
Jan 15 '09 #5

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

Similar topics

3
by: Mike Cocker | last post by:
Hello, I'm quite weak at PHP, so I was hoping to get some help understanding the below code. First off, I'm trying to create a "query form" that will allow me to display the results on my...
5
by: Thejo | last post by:
Hi all, I started programming in PHP recently and have a query about empty $_POST arrays. I can see two scenarios when this could happen. 1. When some tries to directly load the page to which...
6
by: Martin Lacoste | last post by:
Ok, before I headbutt the computer... don't know why when I add criteria in a query, I get an 'invalid procedure call'. I also don't know why after searching the help in access, the various access...
6
by: Andy | last post by:
Hello, I am having many problems with setting up a parameter query that searches by the criteria entered or returns all records if nothing is entered. I have designed an unbound form with 3...
1
by: CCC | last post by:
Our company have used Excel to filter out documents base on date, from_company, type_of_document, country to generate a list of where the documents physical location is. The number of records have...
1
by: Intrepid_Yellow | last post by:
Hi, I have the following code that runs my report generator. The user selects a table from a combo box, then whatever fields they want from a list box. (This part all works and the report runs...
5
by: DeanL | last post by:
Hi all, I'm trying to set up a query that runs from a command button on a form (simple enough so far), what I want the query to do is take values from the fields on the form (seven fields in...
3
by: techmistress | last post by:
Hello, I have a search function, that seems to return all of the records, rather than the ones I query (based on a form). I could use help to find out where I am wrong! $sql = "select * from...
24
by: MU | last post by:
Hello I have some code that sets a dropdownlist control with a parameter from the querystring. However, when the querystring is empty, I get an error. Here is my code: Protected Sub...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
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...
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
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...

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.