I have a query to randomly select 6 images from 3 SQL tables in same database and once someone clicked on that image I want to send them to separate page according from what table that image is selected from. To do that by the query I want to find out the table name which that random image was selected.
My SQL query is
$sql="SELECT *
FROM salehotel
UNION ALL
SELECT *
FROM saleland
UNION ALL
SELECT *
FROM salehouse
ORDER BY RAND()
LIMIT 6
";
$result=mysql_query($sql)or die(mysql_error());
?>
<?php
while($row = mysql_fetch_array($result))
{?>
<div style="float: left; margin-left: 10px;">
<a href="sale_house_detail.php?id=<?php echo $row['property_id']; ?>">
<img src=<?= '"admin/uploads/'.$row['image1'].'"'; ?> width="172px" height="149px" style='border:5px solid #CCC' />
</a>
<p><?php echo $row['Type']; ?></p>
<p><?php echo $row['Location']; ?></p>
</div>
<?php }
?>
Create a new field that indicates the source table in your SQL:
Your PHP can then show this column as: