Dakle imam tri tabele (za sada) i hocu da vrsim pretragu u njima ali samo u odredjenim
poljima.
Ovo ne radi kako treba:
Code:
$q = "SELECT id, title, story FROM ".TBL_STORIES." WHERE ";
$q .= "title LIKE '%$searchphrase%' || story LIKE '%$searchphrase%' ";
$q .= "UNION SELECT id, title, text FROM ".TBL_BEHAVIOR." WHERE ";
$q .= "title LIKE '%$searchphrase%' || text LIKE '%$searchphrase%' ";
$q .= "UNION SELECT id, breed, description FROM ".TBL_BREEDS." WHERE ";
$q .= "breed LIKE '%$searchphrase%' || description LIKE '%$searchphrase%' ";
$q .= "ORDER BY id DESC ";
$q = "SELECT id, title, story FROM ".TBL_STORIES." WHERE ";
$q .= "title LIKE '%$searchphrase%' || story LIKE '%$searchphrase%' ";
$q .= "UNION SELECT id, title, text FROM ".TBL_BEHAVIOR." WHERE ";
$q .= "title LIKE '%$searchphrase%' || text LIKE '%$searchphrase%' ";
$q .= "UNION SELECT id, breed, description FROM ".TBL_BREEDS." WHERE ";
$q .= "breed LIKE '%$searchphrase%' || description LIKE '%$searchphrase%' ";
$q .= "ORDER BY id DESC ";
Podatke parsujem ovako:
Code:
for($i=0; $i<$num_rows; $i++){
$id = mysql_result($result,$i,"id");
$title[] = "<a href=\"/stories.php?id=$id\">".mysql_result($result,$i,"title")."</a>";
$story[] = substr(mysql_result($result,$i,"story"), 0, 200);
$breedname = mysql_result($result,$i,"breed");
$breed[] = "<a href=\"/rasepasa.php?vrsta=pas&rasa=$breedname&id=$id\">$breedname</a>";
$description[] = substr(mysql_result($result,$i,"description"), 0, 200);
}
for($i=0; $i<$num_rows; $i++){
$id = mysql_result($result,$i,"id");
$title[] = "<a href=\"/stories.php?id=$id\">".mysql_result($result,$i,"title")."</a>";
$story[] = substr(mysql_result($result,$i,"story"), 0, 200);
$breedname = mysql_result($result,$i,"breed");
$breed[] = "<a href=\"/rasepasa.php?vrsta=pas&rasa=$breedname&id=$id\">$breedname</a>";
$description[] = substr(mysql_result($result,$i,"description"), 0, 200);
}
Ovi linkovi u rezultatima ne rade kako treba.