Question

Now I'm trying to search in multi table but now my problem how to know which table you got the data ??

$query="(SELECT name  FROM news WHERE name like '%$SER%' ) 
        UNION ALL
        (SELECT name  FROM media WHERE name like '%$SER%') ";
$res=mysql_query($query);
while($row=mysql_fetch_array($res)){
echo $row[prog]."<br>";
}
mysql_num_rows($res);

How to know the result got from which table !!!

Was it helpful?

Solution

Add an extra column

select 1 as FromTable
UNION
select 2 as FromTable;

Anything from the second select will have 2 as $row["FromTable"]

You also NEED to read about SQL injections, and use the mysqli APIs instead ideally (? saves both parsing time, escaping time and the need to escape!)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top