Select from multiple collum from table in db
Posted: Mon Oct 19, 2009 12:37 pm
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.
This is my code:
Thanks for help

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.
This is my code:
Code: Select all
<html>
<head>
</head>
<body>
<?php
$search = $_GET["s"];
?>
<form action="" method="get">
<font face="sans-serif" size="5">
<center>
Doyo - Search Engine project<br>
<input type="text" size="50" name="s" value="<?php echo $search; ?>">
<input type="submit" name="submit" value="Search">
</center>
</font>
<object><hr height="2"></object>
<?php
if(!$search){
}else{
if(strlen($search)<=2){
Echo "Entered keyword is too short. Keyword can not be shorter then two letters.";
}else{
$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%'";
}
}
mysql_connect("mysql.ic.cz", "MYDB", "MYPASS") or die(mysql_error());
mysql_select_db("MYDB") or die(mysql_error());
$run = "SELECT * FROM links WHERE $construct";
$result = mysql_query($run) or die(mysql_error());
while($getrow = mysql_fetch_assoc($result)){
$title = $getrow[title];
$link = $getrow[link];
$desc = $getrow[desc];
echo $title."<br>";
echo $desc."<br>";
echo "<a href="$link">$link</a><br><br>";
}
}
}
?>
</body>
</html>