如何找到图像随机选择的表名 [英] How to find the table name which the image randomly selected from
本文介绍了如何找到图像随机选择的表名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个查询,可以从同一个数据库中的 3 个 SQL 表中随机选择 6 个图像,一旦有人点击了该图像,我想根据选择该图像的表将它们发送到单独的页面.为此,我想通过查询找出选择该随机图像的表名.
我的 SQL 查询是
$sql="SELECT *来自销售酒店联合所有选择 *来自赛尔兰联合所有选择 *从售楼处按兰德 () 排序限制 6";$result=mysql_query($sql)or die(mysql_error());?><?phpwhile($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>
<?php }?>
解决方案
在 SQL 中创建一个指示源表的新字段:
$sql="SELECT salehotel.*, 'salehotel' 作为源来自销售酒店联合所有SELECT saleland.*, 'saleland' 作为源来自赛尔兰联合所有SELECT salehouse.*, 'salehouse' 作为来源从售楼处按兰德 () 排序限制 6";
然后您的 PHP 可以将此列显示为:
<?php echo $row['source'];?>
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:
$sql="SELECT salehotel.*, 'salehotel' as source
FROM salehotel
UNION ALL
SELECT saleland.*, 'saleland' as source
FROM saleland
UNION ALL
SELECT salehouse.*, 'salehouse' as source
FROM salehouse
ORDER BY RAND()
LIMIT 6
";
Your PHP can then show this column as:
<?php echo $row['source']; ?>
这篇关于如何找到图像随机选择的表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文