Hi all,
 
In learning PHP and expanding my (seriously limited) SQL knowledge, I
need to write a query that will look for one or more (can be any number)
of the following fields held in the table:
 
+-------+-------------+
| Field | Type        |
+-------+-------------+
| id    | int(6)      |
| svc   | varchar(20) |
| sev   | tinyint(1)  |
| dsc   | varchar(60) |
| inits | varchar(20) |
| dst   | date        |
| tst   | time        |
| den   | date        |
| ten   | time        |
| res   | tinyint(1)  |
+-------+-------------+
 
I was attempting this using a SELECT command, a WHERE clause, and lots
of LIKE statements.  If search criteria had been entered, the LIKE
statement went along the lines of LIKE('%criteria%'), and if it was
empty, was left with a LIKE('%').  

Yes, it's tragic SQL (one day they may send me on a proper SQL
course...) and naturally, it doesn't work.  The result given is "Empty
Set", even if I only put in one part of search criteria, and if I run a
manual SELECT id,dsc FROM problems WHERE $field
LIKE('%this_criteria_exists%'); it works fine.

I went back and made the query up manually field by field, one field at
a time, adding each LIKE statement in query after query, and found that
after field DSC it failed, with the empty set result.
 
Can anyone point me into the direction of a) Why it fails and b) A
proper query that'll make this work??

All help very gratefully received.

Many thanks in advance 
 
--
Chris Brown
e: ckb@:nospam:.maxnet.eu.org, m: <removed>

Never argue with an idiot, he'll just lower you to his level and beat
you with experience...
 

Reply via email to