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!

Need help with query syntax

Status
Not open for further replies.

Pro777

Programmer
Aug 19, 2003
1
US
Hello,

Ok, here is the scoop, I am a newbie and would greatly appreciate any help you could give.

I have a number of dropdown selectors which are used to search through a database. The default for these hand full of selectors is a wildcard. The variables are set up at the beginning of the results page assigning with $_POST. I am using the following query to bring up a recordset:

"SELECT 'Manufacturer', 'Model/Trim', 'Country', 'Model Year', 'Monitored TM System', 'TM Module Embedded', 'Device Integration', 'E-Call/ACN', 'E-Call/SOS', 'B-Call/Road-Side Assist', 'Remote Diagnostics', 'Door Unlock', 'E-mail', 'Concierge', 'Real-Time Traffic', 'On Board Navi Enable', 'Info Services/Content', 'Web Portal', 'TSP'

FROM 'Master Table'

WHERE Manufacturer = '$varManufacturer', Model/Trim = '$varModel', Country = '$varCountry', Model Year = '$varYear', TSP = '$varTSP'";


All this makes me want to cry...What should I default the 'wildcard' to? Can I just use a *?

Thanks,

Pro777
 
Any columns that aren't constrained by a value should not appear in the WHERE clause at all. There's no such thing as a wildcard. Think of the WHERE clause as a filter: if you don't filter out particular values, you get all of them.

For example, if you want to get all columns from all rows from the table foo where the column bar > 3, you would perform:

select * from foo where bar > 3

But if you don't want want to constrain the selection, don't include a reference to the column in the WHERE clause. If you want to get all columns from all rows in the table foo, you simply perform the query:

SELECT * from foo



Also, in the WHERE clause, you don't separate constraints by commas. You have to use AND or OR, depending on the logic of your query.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top