2017-03-23 2 views
2

Ich habe einen PHP-Code, um die Daten aus der Datenbank mit 2 verschiedenen Tabelle 'tbl_products' & 'tbl_productphotos' mit der gleichen Spalte "ProductID", aber ich kann nicht Bilder von der 'tbl_productphotos' bekommen.Wie erhalten Sie verschiedene Tabellendaten?

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 

meine Frage ist:

<?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)) 
      { 
?> 

& Druck hier:

<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

könnten Sie auch die tilename-Spalte aktualisieren? –

+0

Ja, ich tat, bitte überprüfen – neha

+0

Auch Update während While-Loop-Implementierung –

Antwort

0

Sie alias für den gleichen Spaltennamen definieren könnte: products_ProductID und 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' ";  
+0

nein sir ist nicht funktioniert auch jetzt seine nicht gtting erste Tabelle "tbl_products 'Tabelle andere Details wie Titel, Beschreibung. Bitte überprüfen Sie noch einmal & antworten Sie mir Regards-Cue – neha

0

Diese Abfrage

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

nein Sir funktioniert nicht. Bitte überprüfen Sie noch einmal und Sir eine Sache, die image1. jpeg speichert im Ordner "big" & image2.jeg im Ordner "medium" von ProductID = 36 & impinepant.jpeg speichert im Ordner "big" von ProductID = 37 – neha

+0

Gibt es einen Fehler? – Shyamali

+0

Nein, es hat mir nichts gebracht Fehler, aber nicht bekommen und zeigt Bilder zu – neha

0

titlename Titel sein sollte. Überprüfung unterhalb Abfrage

$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' "; 
+0

nein Sir Titel ist anders & das ist Fliesenname nicht titlename & der Fliesenname ist andere Spalte .Bitte überprüfen Sie wieder nicht funktioniert – neha

0

Versuchen Sie Folgendes:

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

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

+0

Nein Sir nichts passiert. bitte überprüfen Sie noch einmal – neha

+1

Holen Sie sich den ganzen Code bei meinem Github @ https://github.com/aice09/Useful-PHP-Scripts/blob/master/get-diff-tables_data.php – Ace

Verwandte Themen