I am building a search function in my "search.php" for a database in which I am storing information on ip-addresses and various units. Each unit has a "category" column in the database. My search choices are either searching in a text field, and/or selecting a category in a drop-down list. When I choose a category in my drop-down list and not typing anything in the text field, I get the correct results (returning all rows containing the selected category).
But when I type anything in the text field, I don't get any results.
Query when I ONLY choose category(in this case "IP-adress" is chosen as category):
SELECT dataid,
firstname,
lastname,
data.name dataname,
description,
ip,
TYPE,
TIMESTAMP
FROM DATA
INNER JOIN USER ON DATA.userid=USER.userid
WHERE TYPE='IP-adress'
AND DATA.name LIKE '%%'
AND description LIKE '%%'
AND ip LIKE '%%'
AND TYPE LIKE '%%'
AND firstname LIKE '%%'
AND lastname LIKE '%%'
ORDER BY TIMESTAMP DESC
This is returning all rows containing the selected category, as I want to.
Query when I type something in the textfield:
SELECT dataid,
firstname,
lastname,
data.name dataname,
description,
ip,
TYPE,
TIMESTAMP
FROM DATA
INNER JOIN USER ON DATA.userid=USER.userid
WHERE TYPE='IP-adress'
AND DATA.name LIKE '%test%'
AND description LIKE '%test%'
AND ip LIKE '%test%'
AND TYPE LIKE '%test%'
AND firstname LIKE '%test%'
AND lastname LIKE '%test%'
ORDER BY TIMESTAMP DESC
I have combinations where I have columns containing the word "test" just as my input, but I get no results.
I have been at it quite some time now and I am quite sure I had the opposite problem before, where I didn't get any results when I chose a category.
Anyway, I hope another set of eyes could help me out here. If you need more code, just ask for it!