【问题标题】:3 tables, 2x INNER JOIN - but no results3 tables, 2x INNER JOIN - but no results
【发布时间】:2022-12-02 09:37:05
【问题描述】:

I have 2 INNER JOINs. My code is OK, but it shows no results. I do not know what I have done wrong.

<?php
                    
foreach($dbh->query('SELECT 
tbldomainpricing.id,
tbldomainpricing.extension,
tblpricing.type,
tblpricing.relid,
tblpricing.msetupfee,
qi_domainpreise_galerie.tld,
qi_domainpreise_galerie.block,
qi_domainpreise_galerie.blockpos,
qi_domainpreise_galerie.image_thumb
FROM tbldomainpricing
INNER JOIN tblpricing
ON tbldomainpricing.id=tblpricing.relid
INNER JOIN qi_domainpreise_galerie
ON tbldomainpricing.extension=qi_domainpreise_galerie.tld
WHERE tblpricing.type=domainregister
AND  qi_domainpreise_galerie.block=1 
ORDER BY qi_domainpreise_galerie.blockpos ASC') as $row) {

echo '<a class="simple" href="#">
    <div class="tld-tile">
        <img src="uploads_itrena/"'.$row[qi_domainpreise_galerie.image_thumb].'" alt=".'.$row[tbldomainpricing.extension].'" title=".'.$row[tbldomainpricing.extension].'">
        <p class="label">.<span class="name" style="text-transform: uppercase">'.$row[tbldomainpricing.extension].'</span></p>
        <p><b><span class="promo-price" style="color: rgb(255, 0,0);">'.number_format($row[tblpricing.msetupfee], 2, ',', '.').' &euro;</b></span></p>
    </div></a>';
}

There is no output on the site. Replacing

img src="uploads_itrena/"'.$row[qi_domainpreise_galerie.image_thumb].'"

with

img src="uploads_itrena/pic1.png"

shows the tile as desired. So no results are fetched from the database.

  • Do you get results if you run that SELECT query directly on the database? Also, if you add some raw text to your echo line, do you see that on your rendered page?
  • directly in the database PhpMyAdmin alerts "unknown table field 'domainregister' in where clause". But this field definitely is there...!?
  • And when simply raw text is given in the echo, nothing is displayed, too...
  • So now i put "domainregister in quotation marks like this: ...WHERE tblpricing.type="domainregister" Now the query runs properly in PhpMyAdmin,- but with no results
  • Okay,- I found the mistake: "ON tbldomainpricing.extension=qi_domainpreise_galerie.tld" In "tbldomainpricing.extension" the content has leading points, but not in "qi_domainpreise_galerie.tld" For example: ".com" and "com". When deleting this point in the database table everything works fine. But I can't eliminate this point, 'cause it is needed. So how can I tell this to my query?

标签: sql inner-join


【解决方案1】:

Meanwhile I tried something like this:

$users = mysqli_query($db, "SELECT extension FROM tbldomainpricing WHERE id !=''");
while($logins = mysqli_fetch_object($users))
{
$string = "" . $logins->extension . "";
$ergebnis = preg_replace("/[^a-zA-Z]/", "", $string);
                
foreach
($dbh->query('SELECT 
tbldomainpricing.id,
tblpricing.type,
tblpricing.relid,
tblpricing.msetupfee,
qi_domainpreise_galerie.tld,
qi_domainpreise_galerie.block,
qi_domainpreise_galerie.blockpos,
qi_domainpreise_galerie.image_thumb
FROM tbldomainpricing
INNER JOIN tblpricing
ON tbldomainpricing.id=tblpricing.relid
INNER JOIN qi_domainpreise_galerie
ON "'.$ergebnis.'"=qi_domainpreise_galerie.tld
WHERE tblpricing.type="domainregister" AND  qi_domainpreise_galerie.block=1 
ORDER BY qi_domainpreise_galerie.blockpos ASC')as $row) 


echo '<a class="simple" href="#">
    <div class="tld-tile">
        <img src="https://itrena-clients.de/verwaltung/examples/uploads_itrena/'.$row[qi_domainpreise_galerie.image_thumb].'" alt=".'.$row[tbldomainpricing.extension].'" title=".'.$row[tbldomainpricing.extension].'">
        <p class="label">.<span class="name" style="text-transform: uppercase">'. $ergebnis .'</span></p>
        <p><b><span class="promo-price" style="color: rgb(255, 0,0);">'.number_format($row[tblpricing.msetupfee], 2, ',', '.').' &euro;</b></span></p>
    </div></a>';
}
    【解决方案2】:

    Tried to eliminate (replace the leading point) with the first query. But now all the tiles are displayed with the first (same) value from the database.

      猜你喜欢
      • 2013-05-24
      • 1970-01-01
      • 2014-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-12
      • 2020-01-09
      • 2017-12-17
      相关资源
      最近更新 更多