Ok, what I have is a online selling shop. I have items being sold in other locations. I want to display these images
images with information like price and shipping cost and a order button.
So, the problem is that with Mysql 5.0 my query that I pass like
SELECT * FROM ITEMS WHERE country=$country, state= $state , city = $city , zip_code= $zip_code
When I write something like that if any of the where fields are blank it will only grab the items that have those same blank spots.
For example, lest say I selected a country and a state but didn't put a zip code nor a city name. I then expect the results to grab every item being sold in that country and only in that state I selected. Yet, the query dosen't act like this. If the city and zip code are left blank the the query will only grab the items that dosen't have a city name or a zipcode in the data row.
Yet, I need to have it where if those are blank then it means to grab the items based on what was given meaning the country and state.
The only requirement is the countries name. Everything else should be optional. Sometimes if like the city names is blank or null.. then I get a sql query error. I just need to have the query have optional arguments for the where parts or conditional.
My search by default only requires the user to search for items in a country. I have state and region and provance to be optional so that users can narrow down their search towards their local area. If they want to buy something in their local area. Yet, they don't have to always narrow down their searches if they don't want too.
currently I just written a bunch of different SQL queries based on different conditions. yet, this did prevent the query from resulting into an error message but never fixed the search to exactly how I want it to be.
If I had country and state given to the query code. Yet, left city name or zip code to null or blank. then the items listed better have the city name or zip code to null or blank in order for that item to show up in the query.
Yet, I don't want that to happen. I want it where if they left out zip_Code or city name but gave a country name and a state name. Then only return all items being sold in that country under that state. so if it was the U.S and state was Florida and that is what we sent to the query code. Then I expect to see all items being sold in the U.S in the state of Florida to be inside the query or results.
I also want city name and zip code to be optional too. so you don't have to give a zip code or the city name all the time. you can give it the city name or zip code or a zip code range to grab items being cold in that specific area.

New Topic/Question
Reply



MultiQuote





|