Pregunta

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

¿Fue útil?

Solución

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!)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top