Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Query help

Status
Not open for further replies.

Mrtechno

Technical User
Nov 6, 2002
75
NZ
Hey guys... I'm trying to run a SQL Query which is working fine if I pass some search values in the two search textfields of my web page but it doesn't display anything on the page if I leave the textfields blank... This is how the query looks:

SELECT name, dptname FROM testtable WHERE name='gname' AND dptname='dname'

How would you modify this so that it displays all the values in the table if the user doesn't enter anything in the textfields on the webpage?

Thanks.
 
Code:
SELECT name, dptname FROM testtable WHERE 1=1

you then use IF/ELSE clauses in your PHP code to check for the existance of the other variables. if they exist they would be added, if they don't they would be excluded. you append them to your sql code with an AND clause.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top