I have a form with drop down menus to query for name, month, and year
to capture activity accordingly by an individual for a given month and
given year. But I'd like to also be able to query ALL individiduals
for a given month and year OR an individual for the whole year for
example.
My question, is there any way to have blank (not filled in) fields of
a query input ignored when left blank? I'm currently doing very
successfully what I described in the para above but it's taking me 3
queries (which I have on the same sheet for simplicity) to do it when
it would look a lot neater to have a single query and leave any drop
down menu items that I don't want to include on the query, blank and
ignored. Any ideas? TIA 16 2738
so do you have an 'all' option in your drop down ?
what do the three existing queries look like ?
Hello Cover,
$query = "select * from table where 1 = 1 ";
if($name != "") $query .= "and name = '".$name."'" ;
if($month != "") $query .= "and month = '".$month."' ";
if($year != "") $query .= "and year = '".$year."'" ;
Joseph Melnick
JM Web Consultants http://www.jphp.com
"cover" <coverland914 @ yahoo.com> wrote in message
news:1117203234 .674c2d5cd748bf 86b45f941e0b1cb 1fb@teranews... I have a form with drop down menus to query for name, month, and year to capture activity accordingly by an individual for a given month and given year. But I'd like to also be able to query ALL individiduals for a given month and year OR an individual for the whole year for example.
My question, is there any way to have blank (not filled in) fields of a query input ignored when left blank? I'm currently doing very successfully what I described in the para above but it's taking me 3 queries (which I have on the same sheet for simplicity) to do it when it would look a lot neater to have a single query and leave any drop down menu items that I don't want to include on the query, blank and ignored. Any ideas? TIA
I don't see anything wrong with that code. Because you're appending to
the $query var, it's just one single SQL query. But your perl code
(I'm assuming you're using perl) is controlling the query structure.
BTW, I think your code would be more efficient if you used this syntax:
if( $name != '' ) $query .= "and name = '$name'";
or even:
( $name != '' ) && ( $query .= "and name = '$name'" );
Hope this helps.
-Hawk
I don't see anything wrong with that code. Because you're appending to
the $query var, it's just one single SQL query.
BTW, I think your code would be slightly more efficient if you used
this syntax:
if( $name != '' ) $query .= "and name = '$name'";
"jedihawk" <je******@gmail .com> kirjoitti
viestissä:11*** *************** ***@g47g2000cwa .googlegroups.c om... I don't see anything wrong with that code. Because you're appending to the $query var, it's just one single SQL query.
BTW, I think your code would be slightly more efficient if you used this syntax:
if( $name != '' ) $query .= "and name = '$name'";
Forgetting spaces here...
Something more like
if( $name != '' )
$query .= " and name = '$name' "; // padding string with some spaces
So the final query won't be
"select * from table where 1 = 1 and name = '$name'and month = '$month'and
year = '$year'";
but rather
"select * from table where 1 = 1 and name = '$name' and month = '$month'
and year = '$year' ";
--
"I am pro death penalty. That way people learn
their lesson for the next time." -- Britney Spears et************* ***@5P4Mgmail.c om
What wonderful code - talk about slick... :-) don't quite understand
what the "from table where 1 = 1" is doing (the business with the '1'
but it sure works great - thanks so much...
A second question since this bit of magic happened so fast and if you
have a moment... On a database with name, month, year and so on is
days (as in days taken off). The query runs very nicely but I'd love
to have a total at the bottom of the query page.
name, date, days, notes pretty much comprise it with 1, 2, 3, and so
on being entered into a mysql database varchar field for the numbers.
Is adding the totalizer relatively easy on a query? I have what I
think is a pretty good book on PHP & mysql but haven't been able to
find any answer there.
thanks,
Chris (cover)
just changed my newserver
On Fri, 27 May 2005 11:56:16 -0400, "Joseph Melnick"
<jm******@jphp. com> wrote: Hello Cover,
$query = "select * from table where 1 = 1 "; if($name != "") $query .= "and name = '".$name."'" ; if($month != "") $query .= "and month = '".$month."' "; if($year != "") $query .= "and year = '".$year."'" ;
Joseph Melnick JM Web Consultants http://www.jphp.com
Chris (co**********@y ahoo.com) wrote:
: What wonderful code - talk about slick... :-) don't quite understand
: what the "from table where 1 = 1" is doing (the business with the '1'
: but it sure works great - thanks so much...
WHERE 1 = 1 (i.e. where one equals one)
is always true.
It is the same as having no where clause, except that you can append
something like
" AND name='fred' "
and the statement will still work.
WHERE 1 = 1 AND name='fred'
Otherwise you need to worry about adding the WHERE clause and when to add
the AND.
It is a useful idiom, nothing more.
--
This space not for rent.
I really do appreciate ALL of your replies, guys - thanks so much...
I've gained from all of them as I learn more about PHP.
Chris
Hello Kimmo,
You are correct. missing spaces are another trap.
Adding white space between clauses is important.
Thank you for noticing.
Joseph Melnick
"Kimmo Laine" <et************ *******@Mgmail. com> wrote in message
news:d7******** **@phys-news1.kolumbus. fi... "jedihawk" <je******@gmail .com> kirjoitti viestissä:11*** *************** ***@g47g2000cwa .googlegroups.c om...I don't see anything wrong with that code. Because you're appending to the $query var, it's just one single SQL query.
BTW, I think your code would be slightly more efficient if you used this syntax:
if( $name != '' ) $query .= "and name = '$name'";
Forgetting spaces here...
Something more like if( $name != '' ) $query .= " and name = '$name' "; // padding string with some spaces
So the final query won't be "select * from table where 1 = 1 and name = '$name'and month = '$month'and year = '$year'";
but rather "select * from table where 1 = 1 and name = '$name' and month = '$month' and year = '$year' "; -- "I am pro death penalty. That way people learn their lesson for the next time." -- Britney Spears
et************* ***@5P4Mgmail.c om This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: majsen |
last post by:
Hi, I have problem running this query. It will time out for me...
My database are small just about 200 members.
I have a site for swaping appartments (rental). my query should look
for match
in a triangle. Like this member A -> B->C
A give his appartment to B. B gives his appartment to C and finally
C gives his appartment to A
Soo my query looks for matching parameters like rooms, location, size
|
by: Együd Csaba |
last post by:
Hi All,
how can I improve the query performance in the following situation:
I have a big (4.5+ million rows) table. One query takes approx. 9 sec to
finish resulting ~10000 rows. But if I run simultaneously 4 similar queries
it takes nearly 5 minutes instead of 4 times 9 seconds or something near of
that.
here is a sample query:
select mertido, fomeazon, ertektipus, mertertek from t_me30 where fomeazon
in (select distinct fomeazon...
|
by: John Ortt |
last post by:
> I have a table of dates in ascending order but with varying intervals. I
> would like to create a query to pull out the date (in field 1) and then
pull
> the date from the subsequent record (and store it in field 2).
>
> I would like to run a query that returns all the data in the table plus
the
> record number, in a similar sense to the getuser() command to get the
User's
> Identity, I would like a GetRecord() command.
|
by: Ekqvist Marko |
last post by:
Hi,
I have one Access database table including questions and answers. Now
I need to give answer id automatically to questionID column. But I
don't know how it is best (fastest) to do?
table before
rowID answID qryrow questionID datafield
1591 12 06e 06e 06e question
1593 12 06f 06f 06f question
1594 12 answer to the question 06f
|
by: serge |
last post by:
How can I run a single SP by asking multiple sales question either
by using the logical operator AND for all the questions; or using
the logical operator OR for all the questions. So it's always
either AND or OR but never mixed together.
We can use Northwind database for my question, it is very similar
to the structure of the problem on the database I am working on.
IF(SELECT OBJECT_ID('REPORT')) IS NOT NULL
DROP TABLE REPORT_SELECTION
| |
by: jjturon |
last post by:
Can anyone help me??
I am trying to pass a Select Query variable to a table using Dlookup
and return the value to same select query but to another field.
Ex.
SalesManID SalesManName
AT Alan Time
|
by: mmitchell_houston |
last post by:
I'm working on a .NET project and I need a single query to return a
result set from three related tables in Access 2003, and I'm having
trouble getting the results I want.
The details:
Question ------------
QuestionID
QuestionText
Question_MediaTypeID
|
by: Stan |
last post by:
I am working with Access 2003 on a computer running XP. I am new at
using Access. I have a Db with a date field stored as mm/dd/yyyy. I
need a Query that will prompt for the month, ie. 6 for June, and will
return all records in that month.
|
by: Richard Hollenbeck |
last post by:
I am very sorry about the (almost) re-post, but you will see that my first
question wasn't very clear; I have another question I posted this morning
called, "in DAO: Run time error 3061 Too few parameters...."
I have read many articles on the web about how to make a dynamic report
based on a cross-tab query. But for some reason mine never works right.
First, my saved query's criteria is the data in an open form's combo box.
So the...
|
by: ARC |
last post by:
Hello all,
So I'm knee deep in this import utility program, and am coming up with all
sorts of "gotcha's!".
1st off. On a "Find Duplicates Query", does anyone have a good solution for
renaming the duplicate records? My thinking was to take the results of the
duplicate query, and somehow have it number each line where there is a
duplicate (tried a groups query, but "count" won't work), then do an update
query to change the duplicate to...
|
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,...
| |
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...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |