如何在PHP/MYSQL中获得不同的ID值?
我有PHP代码从数据库中获取两个表“tbl_products”和“tbl_productphotos”数据。我想获取不同的数据。 我的查询和代码是:如何在PHP/MYSQL中获得不同的ID值?,php,mysql,Php,Mysql,我有PHP代码从数据库中获取两个表“tbl_products”和“tbl_productphotos”数据。我想获取不同的数据。 我的查询和代码是: <?php $sql = "select DISTINCT t1.*,t2.photo from tbl_products t1, tbl_productphotos t2 where t1.ProductID = t2.ProductID and t1.tilename = 'Glass
<?php
$sql = "select DISTINCT t1.*,t2.photo
from tbl_products t1, tbl_productphotos t2
where t1.ProductID = t2.ProductID
and t1.tilename = 'Glass Tile'
and t1.ProductID = t2.ProductID
ORDER BY ProductID DESC";
$qex=mysql_query($sql);
while($row=mysql_fetch_array($qex))
{
?>
<input type="hidden" value="<?php echo $row['ProductID'];?>">
<li class="col-md-3 col-sm-6 col-xs-12 isotope-item websites" style="float: left">
<div class="portfolio-item">
<span class="thumb-info thumb-info-lighten thumb-info-bottom-info thumb-info-centered-icons">
<span class="thumb-info-wrapper">
<img src="images/products/thumbs/<?php echo $row['photo']; ?>" class="img-responsive" alt="" height="200px" width="200px">
<span class="thumb-info-title">
<span class="thumb-info-inner"><?php echo $row['Title'];?></span>
<span class="thumb-info-type"><?php echo substr($row['Description'],0 ,37);?></span>
</span>
<span class="thumb-info-action">
<a href="glass-tile-details.php?ProductID=<?php echo base64_encode($row['ProductID']); ?> "&< ÃΧ!ϒυ "&>€ ÁÂ"& ´Æ©"&& "ÉϖΠ 1"&ϑΘ "&"><span class="thumb-info-action-icon thumb-info-action-icon-primary"><i class="fa fa-link"></i></span>
</a>
<a href="images/products/thumbs/<?php echo $row['photo']; ?>" style="width: 500px; height: 500px;" class="lightbox-portfolio">
<span class="thumb-info-action-icon thumb-info-action-icon-light"><i class="fa fa-search-plus"></i></span>
</a>
</span>
</span>
</span>
</div>
</li>
<?php
}
?>
第二表:“tbl_产品照片”
我们可以选择多个图像我选择3个图像和所有3个存储在所有三个文件夹中的图像。所以我只想用一个ProductID只获得一张带有详细信息的图片,但我在网页上显示了所有3张图片
请检查、回复并帮助我。
谢谢和问候
Ankit尝试避免选择*。
(条件t1.ProductID=t2.ProductID有两次)
尽快
?我不记得你雇用过任何人。我们不是你的工作猴子。t2。照片
在所有行中都是一样的。你不应该得到3份。它们应该是不同的照片吗?如果是,它应该返回哪一个?对不起,先生,我是这里的新用户,从现在起,我将永远不会尽快写这个。问候-ankit您不需要在WHERE
子句中有t1.ProductID=t2.ProductID
两次。使用GROUP BY t1.ProductID
而不是SELECT DISTINCT
。很抱歉,即使使用此查询,它也不起作用。我会得到一个空白屏幕。请更新您的问题,并添加您现在取消的确切查询代码..请。。anc检查错误和相关消息。。为了避免歧义,我还按列顺序更新了答案
ProductID Title Description titlename
35 ABC tile Glass Tile
36 XYZ tile 2 Glass Tile
id ProductID photo Each Image store in 3 folders
5 35 image.jpeg (in folder big,medium,thumbs)
6 35 image.jpeg (in folder big,medium,thumbs)
7 35 image.jpeg (in folder big,medium,thumbs)
8 36 image.jpeg (in folder big,medium,thumbs)
9 36 image.jpeg (in folder big,medium,thumbs)
10 36 image.jpeg (in folder big,medium,thumbs)
$sql = "select DISTINCT
t1.ProductID,
t1.Title,
t1.titlename,
t1.Description,
t2.photo
from tbl_products t1
INNER JOIN tbl_productphotos t2 on t1.ProductID = t2.ProductID
and t1.tilename = 'Glass Tile'
ORDER BY t1.ProductID DESC";