moving companies : Computers : Programming : Languages : PHP : Database Backed Sites : General

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

66 of 84 people (79%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How can I search a database for part of a string?
How do I use LIKE in a query?
What is the wildcard symbol in SQL?
How to speed up a like??
How to create an query that uses like and or that doesn't take forever to return reuslts?
How to create an or query with using a like?

Jun 27th, 1999 17:27
Nathan Wallace, Web Boy, Ben Udall, Adam Whitehead, Nick Talbott


To do substring searches you can use:
$result = mysql_query("
    select * from schools where code LIKE '%$search%'");
NOTE: % is the SQL "wildcard" symbol
This will find all rows in the table schools where the column code
contains the string stored in the variable $search.
Careful though, LIKE is quite slow .. and LIKE %abc% queries cannot be
indexed with MySQL.