Altamash Altamash - 1 month ago 7
MySQL Question

Search more then one MySql table in Mysql Database PHP


I have a database have 20 tables i want to search all of these i got stuck that how can i search this and solve this query help is very appreciated.
like
Blockquote



  1. table1

  2. table2

  3. table3

  4. table4




and so one. this is my script.


<?php
if(isset($_GET["search"]))
{
$condition = '';
//$query = explode(" ", $_GET["search"]);
$query = explode(" ", $_GET["search"]);

foreach($query as $text)
{
$condition .= "`title` LIKE +'%".mysqli_real_escape_string($connect, $text)."%' OR ";
}
$condition = substr($condition, 0, -4);
$sql_query = "SELECT * FROM countries2 WHERE " . $condition;
$result = mysqli_query($connect, $sql_query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
echo '<tr><td>'.$row["title"].'</td></tr>';
}
}
else
{
echo '<label>Data not Found</label>';
}
}
?>

Answer

Try with this

sql_query = "SELECT * FROM `countries`,`countries2`   WHERE " . $condition;  

i have noticed that you are making a search directory or something like this.

you may use FULLTEXT SEARCH with operators and Stemming after this your query will look like this. implement as per your requirement ;).

(SELECT * FROM table1 WHERE(col1,col2,clo3) AGAINST(."$search".) IN NATURAL LANGUAGE MODE)
Comments