我有一个PHP代码来从数据库中获取数据,其中包含2个不同的表'tbl_products'& 'tbl_productphotos'具有相同的列“ProductID”,但我无法从'tbl_productphotos'获取图像。
tables data is: 'tbl_products'
ProductID Title Description tilename
36 T-shirt T-Shirt Red Glass Tile
37 Pant Pant Black Glass Tile
'tbl_productphotos'
id ProductID photo
1 36 image1.jpeg
2 36 image2.jpeg
3 37 imagepant.jpeg
我的查询是:
<?php
$sql="select tbl_products.*,tbl_productphotos.* from tbl_products inner join tbl_productphotos on tbl_products.ProductID=tbl_productphotos.ProductID where tbl_products.tilename='Glass Tile' ";
$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/big/<?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="portfolio-single-project.html">
<span class="thumb-info-action-icon thumb-info-action-icon-primary"><i class="fa fa-link"></i></span>
</a>
<a href="img/projects/project.jpg" 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
}
?>
答案 0 :(得分:0)
您可以为同一列名定义别名:productphotos_ProductID
和$sql = "select tbl_products.*,tbl_productphotos.*, tbl_products.ProductID as products_ProductID, tbl_productphotos.ProductID as productphotos_ProductID from tbl_products inner join tbl_productphotos on tbl_products.ProductID=tbl_productphotos.ProductID where tbl_products.tilename='Glass Tile' ";
。
var skill_f = $("#table_display_skills tr").find('td:nth-child(1)').text().trim();
var importanceSkill_f = $("#table_display_skills tr").find('td:nth-child(2)').text().trim();
var industry_f = $("#table_display_industry tr").find('td:nth-child(1)').text().trim();
var importanceIndustry_f = $("#table_display_industry tr").find('td:nth-child(2)').text().trim();
var education_f = $("#table_display_education tr").find('td:nth-child(1)').text().trim();
var importanceEducation_f = $("#table_display_education tr").find('td:nth-child(2)').text().trim();
答案 1 :(得分:0)
尝试此查询
$sql = "select t1.*,t2.*
from tbl_products t1, tbl_productphotos t2
where t1.ProductID = t2.ProductID
and t1.tilename = 'Glass Tile'
and t1.ProductID = 36";
答案 2 :(得分:0)
titlename应该是Title。检查以下查询
$sql="select tbl_products.*,tbl_productphotos.* from tbl_products inner join tbl_productphotos on tbl_products.ProductID=tbl_productphotos.ProductID where tbl_products.Title='Glass Tile' ";
答案 3 :(得分:0)
尝试以下方法:
$ sql =&#34; SELECT * FROM tbl_products INNER JOIN tbl_productphotos ON tbl_productphotos.ProductID = tbl_productphotos.ProductID&#34;;
$ sql =&#34; SELECT * FROM tbl_products,tbl_productphotos WHERE tbl_products.ProductID = tbl_productphotos.ProductID&#34 ;;