i have to search in multiple tables :
$query ="(SELECT *, 'product' AS type FROM products WHERE title LIKE ? OR description LIKE ? OR full_description LIKE ? OR keywords LIKE ? OR option1 LIKE ? OR option2 LIKE ? OR option3 LIKE ? OR option4 LIKE ? OR option5 LIKE ? OR option6 LIKE ? OR option7 LIKE ? OR option8 LIKE ?)
UNION
(SELECT *, 'article' AS type, NULL AS image1, NULL AS image2, NULL AS image3, NULL AS image4 FROM articles WHERE title LIKE ? OR description LIKE ? OR full_description LIKE ? OR keywords LIKE ? OR option1 LIKE ? OR option2 LIKE ? OR option3 LIKE ? OR option4 LIKE ? OR option5 LIKE ? OR option6 LIKE ? OR option7 LIKE ? OR option8 LIKE ?)
UNION
(SELECT *, 'news' AS type, NULL AS image1, NULL AS image2, NULL AS image3, NULL AS image4 FROM news WHERE title LIKE ? OR description LIKE ? OR full_description LIKE ? OR keywords LIKE ? OR option1 LIKE ? OR option2 LIKE ? OR option3 LIKE ? OR option4 LIKE ? OR option5 LIKE ? OR option6 LIKE ? OR option7 LIKE ? OR option8 LIKE ?)
UNION
(SELECT *, 'page' AS type, NULL AS categoryID, NULL AS categoryName, NULL AS full_description, NULL AS image, NULL AS image1, NULL AS image2, NULL AS image3, NULL AS image4, NULL AS price FROM pages WHERE title LIKE ? OR description LIKE ? OR option1 LIKE ? OR option2 LIKE ? OR option3 LIKE ? OR option4 LIKE ? OR option5 LIKE ? OR option6 LIKE ? OR option7 LIKE ? OR option8 LIKE ?)
UNION
(SELECT *, 'gallery_image' AS type, NULL AS categoryID, NULL AS categoryName, NULL AS full_description, NULL AS image1, NULL AS image2, NULL AS image3, NULL AS image4, NULL AS price FROM gallery_images WHERE title LIKE ? OR description LIKE ? OR option1 LIKE ? OR option2 LIKE ? OR option3 LIKE ? OR option4 LIKE ? OR option5 LIKE ? OR option6 LIKE ? OR option7 LIKE ? OR option8 LIKE ?)";
$selectFromTables = $this->db->prepare($query);
$selectFromTables->execute(array("%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%", "%" . $keyword . "%"));
$found = $selectFromTables->rowCount();
while($rowSearch = $selectFromTables->fetch(PDO::FETCH_ASSOC))
{
$id = $rowSearch['id'];
$type = $rowSearch['type'];
$title = $rowSearch['title'];
echo $id . "->" . $type . "<br />";
}
why while loop return this output?
23->product
24->product
25->product
27->product
28->product
1->
1->
2->
4->
5->
but i expect this output :
23->product
24->product
25->product
27->product
28->product
1->article
1->news
2->page
4->page
5->page