November 3rd, 2004, 05:36 PM
Dynamically Building a Select Statement
I'm creating a search form with different fields that you can search for (i.e. FirstName, LastName, Country, etc). Anybody have an idea on how I can create a dynamic select statement that can include all of the fields or just 1 of the fields in the search query depending on what field the user fills out?
Any help would be greatly appreciated. Thanks!
November 3rd, 2004, 05:56 PM
November 3rd, 2004, 06:24 PM
basically the select statement will look something like this:
(if FirstName, LastName, Country where filled out)
select * from table where FirstName like "blah" and where LastName like "blah" and where Country like "blah"
(if only Firstname was filled out)
select * from table where FirstName like "blah"
i guess you get the idea...any thoughts?
November 3rd, 2004, 08:13 PM
The data from a form is used to construct an SQL query.
You need the appropriate module (something like mysqldb). Here is a tutorial that walks you through it:
November 4th, 2004, 03:27 AM
We also have a nice article that describes how to use MySQLdb in Devsheds Python section:
November 4th, 2004, 03:25 PM
Thanks guys. I'll try it out.