TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 05-31-2009, 06:46 AM   #1 (permalink)
The Contributor
 
Join Date: Feb 2007
Posts: 64
Thanks: 9
Killswitch is on a distinguished road
Default Searching with multiple options

I have run into a problem with an app I am working on. I am trying to do a search. I had the basic search down, but I am trying to let people search with multiple options, basically searching in certain fields. If you can point me in the right direction, then many thanks.

Basically, I have an auto database; a stock number, a manufacturer, a model, vin, price, and a year. User can search and I have checkboxes for each of these to include in the search.

I just can't figure out how to form the query. I tried joining them with .= and the ||, but not working right. Basically, I had the intial SELECT FROM WHERE, then checked if each post was set and if so conjoined the query with .= ..

Code:
$query = "SELECT stock_number, manufacturer, model, price, vin, year FROM #__inventory WHERE ";
				if( isset( $_POST['stock_number'] ) ) {
					$query .= "\n `stock_number` LIKE '%$search%'";
				}
				if( isset( $_POST['manufacturer'] ) ) {
					$query .= "\n`manufacturer` LIKE '%$search%'";
				}
				if( isset( $_POST['model'] ) ) {
					$query .= "\n || `model` LIKE '%$search%'";
				}
				if( isset( $_POST['price'] ) ) {
					$query .= "\n || `price` LIKE '%$search%'";
				}
				if( isset( $_POST['vin'] ) ) {
					$query .= "\n || `vin` LIKE '%$search%'";
				}
				if( isset( $_POST['year'] ) ) {
					$query .= "\n || `year` LIKE '%$search%'";
				}
It failed, since if some weren't checked then the || voided everything.

Can anyone help advise on this?
Killswitch is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Mail - Help sending multiple attachments xperience Absolute Beginners 5 09-06-2010 08:27 AM
inserting multiple checkbox selections on one row sarmenhb Absolute Beginners 3 01-10-2009 07:32 PM
Passing multiple arguments to a function via one variable. delayedinsanity Advanced PHP Programming 10 05-07-2008 05:04 AM
Storing multiple file paths inside a database Orc General 10 02-17-2008 04:29 AM
Multiple Servers? Sam Granger Advanced PHP Programming 5 02-08-2008 03:14 PM


All times are GMT. The time now is 09:01 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design