Ahmad Afzaal Ahmad Afzaal - 1 month ago 6
HTML Question

How to search multiple table in PHP MYSQL

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.

This is my script:

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 table 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

I recommend using a view: http://www.w3schools.com/sql/sql_view.asp

Then you'll have just one thing to search in. Hope it helped. c:

Comments