MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 18th, 2000, 10:56 AM
SoccerFan SoccerFan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2000
Posts: 11 SoccerFan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I'd really appreciate responses on how to do this:

I'm trying to select records based on multiple critera.

$test is a variable that comes in from a form.

$query2 = "SELECT * FROM trovemain WHERE (cata LIKE '%$test%')";

This is selecting anything that has $test anywhere in the field "cata".

Two questions:

1. will this pick up fields that start or end with $test?

2. How can I do some logical operators like AND and OR.

I'd like to use not just $test, but about 10-15 variables and select out records that have variableA AND variableB AND variableC OR variableD

I can't figure out how to do this...

your help is appreciated.

Reply With Quote
  #2  
Old October 18th, 2000, 03:58 PM
Kyuzo Kyuzo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 1999
Location: Annapolis, Maryland US
Posts: 113 Kyuzo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
1. will this pick up fields that start or end with $test?

>> should do both

2. How can I do some logical operators like AND and OR.

<?
$searchlist=array("cat", "dog", "mouse");

$query="SELECT * from trovemain WHERE ";
for($i=0;$i<count($searchlist); $i++)
$query.="cata LIKE '%$searchlist[$i]%' OR ";
$query=substr($query, 0 -3); // strip off last 'OR '
$query.=" order by some_column";

//run the query
?>

You can make the $searchlist array an array of variables from the form.

You could also include a radio button saying "Search by ALL terms" (AND) or "Search by ANY term" (OR) - this will give you the ability to choose AND or OR for your query syntax.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Multiple Searches in MySQL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT