Ive got the following search script that seaches my tables in my db and outputs the results. I need to know how to identify which table the result comes from and then add the oppropriate link by id to view the actual data. I have reseached and i know i need a discriminator to identify the tables but have no idea how to implement it with the href links. Can someone please assist me.
<?php
include'db.php';
if(!empty($_POST))
{
$aKeyword = explode(" ", $_POST['keyword']);
$query ="SELECT * FROM tbl_articles WHERE name like '%" . $aKeyword[0] . "%'
UNION
SELECT * FROM tbl_album WHERE name like '%" . $aKeyword[0] . "%'
UNION
SELECT * FROM tbl_gallery WHERE gname like '%" . $aKeyword[0] . "%'
UNION
SELECT * FROM tbl_events WHERE name like '%" . $aKeyword[0] . "%'";
for($i = 1; $i < count($aKeyword); $i++) {
if(!empty($aKeyword[$i])) {
$query .= " OR name like '%" . $aKeyword[$i] . "%'";
}
}
$result = $db->query($query);
echo "<br>You have searched for keywords: " . $_POST['keyword'];
if(mysqli_num_rows($result) > 0) {
$row_count=0;
echo "<br>Result Found: ";
While($row = $result->fetch_assoc()) {
$row_count++;
$id = $row['artid'];
$name = $row['name'];
echo "<a href='results.php?id=$id'>$name</a>";
}
}
else {
echo "<br>Result Found: NONE";
}
}
?>
So if the author column of your result is not null, it’s an article.
If the image column of your result is not null, it’s an album.
If the gname of the result is not null, it’s a gallery
Otherwise, it’s an event.
When a search is conducted and the result for example comes from the tbl_articles table i need the source table to be identified and linked to the relavent article page. something along the lines if($row == tbl_articles{
echo “$row[‘name’]”;
else if($row ==tble_gallery{
echo "Row[‘gname’];
i can then just add an href link. At least thats what my logic is telling me however im unsure of how to go about it.