sql query help (very specific)
I have looked all over the internet for an answer to my question to why my sql statement returns false. I checked it out on the sql validator over at mimer and all I got was that I used the reserved word name. There should be something in my databa开发者_Go百科se that matches this so here it is:
Here is how I create the sql statement:
$title = 'SELECT * FROM item, categories WHERE item.title
LIKE "%'.implode('%" OR item.title LIKE "%', $data).'%"'.'
AND categories.name = '.$category;
And this is the result:
SELECT * FROM item, categories WHERE item.title LIKE "%hello%"
OR item.title LIKE "%world%" OR item.title
LIKE "%Joomla%" OR item.title LIKE "%Animal%" AND categories.name = Book
You should probably think about your (lack of) parentheses. I'm not sure specifically what you are trying to accomplish,
but this:
SELECT
*
FROM item, categories
WHERE item.title LIKE "%hello%"
OR item.title LIKE "%world%"
OR item.title LIKE "%Joomla%"
OR item.title LIKE "%Animal%"
AND categories.name = "Book"
is vastly different from this:
SELECT
*
FROM item, categories
WHERE (
item.title LIKE "%hello%"
OR item.title LIKE "%world%"
OR item.title LIKE "%Joomla%"
OR item.title LIKE "%Animal%"
)
AND categories.name = "Book"
Also, like the others say, Book should be in quotes (like I have done here).
AND categories.name = "Book"
You need to surround the word Book
with quotes.
I'm betting you also need parentheses.
SELECT * FROM item, categories WHERE (item.title LIKE "%hello%"
OR item.title LIKE "%world%" OR item.title
LIKE "%Joomla%" OR item.title LIKE "%Animal%") AND categories.name = "Book"
the last part, categories.name, is that a string? if so it should be
and categories.name = 'book'
note the quotes around book
精彩评论