Hi all. my problem is this:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc LIKE '%video%' OR title LIKE '%video%' OR keywords LIKE '%share%' OR desc L' at line 1
it is for my SE (search engine)
i using php and mysql 2 years but this is first time when i need to select data from multiple collum.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc LIKE '%share%' OR title LIKE '%share%'' at line 1
mysql_connect("mysql.ic.cz", "user", "pw") or die(mysql_error());
mysql_select_db("ic_getvideo") or die(mysql_error());
$search = $_GET["s"];
$search_explode = explode(" ", $search);
foreach($search_explode as $search_each){
$x++;
if($x == 1){
$construct .= "keywords LIKE '%$search_each%' OR desc LIKE '%$search_each%' OR title LIKE '%$search_each%'";
}else{
$construct .= " OR keywords LIKE '%$search_each%' OR desc LIKE '%$search_each%' OR title LIKE '%$search_each%'";
}
}
$run = "SELECT * FROM links WHERE $construct";
$result = mysql_query($run) or die(mysql_error());
var_dump($result);
if($x == 1){
$construct .= "keywords LIKE '%$search_each%'";
}else{
$construct .= " OR keywords LIKE '%$search_each%'";
}
}
This works, but I need to find keywords from the title and desc and from keywords and not only keywords.
Other info.:
my db structure:
database ic_getvideo with table links and there are collum: id, url, title, desc, keywords
First of all, you're not giving us the information that we might use to help you. Show us what your SQL string looks like just before you try to run your query!
Whenever you get a MySQL error message like that, it means that the error has occurred just before the part of the SQL that is quoted. Just knowing that, my first guess is that you are not getting a value for your first keyword, so your SQL string probably looks like:
SELECT * FROM links WHERE [b][color=#FF0000]`[/color][/b][color=#0000FF]keywords[/color][b][color=#FF0000]`[/color][/b] LIKE '%$search_each%' OR [color=#FF0000][b]`[/b][/color][color=#0000FF]title[/color][color=#FF0000][b]`[/b][/color] LIKE '%$search_each%' OR `desc` LIKE '%$search_each%'
SELECT * FROM links WHERE [color=#0000FF]keywords[/color] LIKE '%$search_each%' OR [color=#0000FF]title[/color] LIKE '%$search_each%' OR [color=#0000FF]desc[/color] LIKE '%$search_each%'