我在mysql中有联合表,但我需要获取名称表来显示我的数据。 这里是mysql代码
$blog = mysql_query("SELECT gambar FROM life
UNION ALL
SELECT gambar FROM places
UNION ALL
SELECT gambar FROM style
UNION ALL
SELECT gambar FROM art
order by RAND() ");
然后在php中他们显示但我的图像有问题,因为基于表名的不同文件夹中的图像 这里是我的PHP代码
$tes = mysql_query("SELECT gambar FROM life
UNION ALL
SELECT gambar FROM places
UNION ALL
SELECT gambar FROM style
UNION ALL
SELECT gambar FROM art
order by RAND() ");
while($b=mysql_fetch_array($tes)){
echo "<img src='img/table_name/$b[pic]'>";
}
“table_name”它应该是联合表上数据的表名
答案 0 :(得分:1)
我认为你可以将它添加到子查询中:
SELECT judul, 'life' as table_name FROM life
UNION ALL
SELECT judul, 'places' FROM places
UNION ALL
SELECT judul, 'style' FROM style
UNION ALL
SELECT judul, 'art' FROM art
order by RAND()