【问题标题】:How to get different tables data?如何获取不同的表数据?
【发布时间】:2017-08-15 12:58:42
【问题描述】:

我有一个 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
                        }
                    ?>

【问题讨论】:

  • 你也可以更新 tilename 列吗?
  • 是的,请检查
  • 同时更新while循环实现
  • 正如您从对问题的各种编辑中看到的那样,我们不会在此处添加“尽快”和签名。这已经对你说过好几次了,所以我们现在进入了一个你故意这样做的地方,然后等待志愿者编辑来清理你一直在制造的烂摊子。如果您坚持下去,您的反对票数将达到您自动禁止提问的程度。因此,写出更好的问题并停止寻求帮助确实符合您自己的利益。

标签: php jquery html css


【解决方案1】:

您可以为同一列名称定义别名:products_ProductIDproductphotos_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' ";    

【讨论】:

  • 不,先生,即使现在它也无法正常工作,它没有获得第一张表“tbl_products”表的其他详细信息,例如标题,描述。请再次检查并回复我问候-提示
【解决方案2】:

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' "; 

【讨论】:

  • no sir Title 不同,即 tilename 不是 titlename,并且 tilename 列不同。请再次检查无效
【解决方案3】:

试试这个查询

$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";

【讨论】:

  • 不,先生不工作。请再次检查,先生,image1.jpeg 将存储在 ProductID = 36 的文件夹“medium”中的文件夹“big”和 image2.jeg 中,并且 imagepant.jpeg 将存储在 ProductID = 37 的文件夹“big”中
  • 不,它没有给我任何错误。但也没有获取和显示图像
  • 是的,先生,我多次尝试从“大”文件夹中获取图像及其工作并在屏幕上显示图像。但是通过查询它获取第一个表数据(标题和描述)而不是表 2 中的图像,只显示带有该图标的图像空间,如果找不到图像,它会向我们显示。请检查并回复我先生。 bcz 这不是一件大事,我们在那里缺少一件小事。问候 - 提示
  • 不,先生仍然没有得到图像先生,向我显示标题和描述,但没有图像。请再次检查
  • 你能不能把查询结果var_dump出来并评论一下
【解决方案4】:

尝试以下方法:

  1. $sql= "SELECT * FROM tbl_products INNER JOIN tbl_productphotos ON tbl_productphotos.ProductID= tbl_productphotos.ProductID";

  2. $sql="SELECT * FROM tbl_products ,tbl_productphotos WHERE tbl_products.ProductID =tbl_productphotos.ProductID";

【讨论】:

猜你喜欢
  • 2017-08-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-24
相关资源
最近更新 更多