php - SQL打印表不起作用

标签 php html sql mysqli html-table

我在打印表格时遇到问题。我知道我的 SQL 查询有效,但我的网站上没有显示任何内容。我对 PHP 和 SQL 有点陌生,现在我被困住了。非常感谢有关我的代码的任何提示!

$setidquery = "SELECT
                inventory.quantity,
                inventory.itemid,
                inventory.colorid,

                parts.partname,
                sets.setid,
                inventory.itemtypeid
                FROM
                inventory
                join
                parts
                on inventory.itemid = parts.partid
                join
                colors
                on inventory.colorid = colors.colorid
                join
                sets
                on inventory.SetID = sets.SetID
                where
                  sets.setid = '$_COOKIE[setid]'
                order by
                partname asc
            limit 1000";

我在这里尝试获取正确的图像。

echo "<table class=\"table\">";
  echo "<tr><th>Quantity:</th><th>Partname:</th><th>ItemID:</th><th>SetID</th><th>Image:</th></tr>";

  while($row = mysqli_fetch_array($result)){

      $prefix = "http://www.itn.liu.se/~stegu76/img.bricklink.com/";

      $Quantity = $row['Quantity'];
      $ItemID = $row['ItemID'];
      $ColorID = $row['ColorID'];


      $ItemtypeID = $row['ItemtypeID'];

      $imagesearch = mysqli_query($conn, "SELECT * FROM `images` WHERE ItemTypeID = '$ItemtypeID' AND ItemID = '$ItemID' AND ColorID = '$ColorID' ");

      $imageinfo = mysqli_fetch_array($imagesearch);

      if($imageinfo['has_jpg']) {
        $filename = "$ItemtypeID/$ColorID/$ItemID.jpg";
      } else if($imageinfo['has_gif']) {
        $filename = "$ItemtypeID/$ColorID/$ItemID.gif";
      } else {
        $filename = "noimage_small.png";
      }

      $SetID = $row['SetID'];
      $Partname = $row['Partname'];
      echo "<tr>
              <td>$Quantity</td>
              <td>$Partname</td>
              <td>$ItemID</td>
              <td>$SetID</td>
              <td><img src=\"$prefix$filename\" alt=\"Part $ItemID\"/></td>
            </tr>";
  }
      echo "</table>";

然后打印所有内容。

在网站上它看起来像这样:

Part of the table

最佳答案

在 PHP 中,变量数组键 区分大小写。

您正在从 SQL 获取 itemid 并使用 ItemID 访问它。

所以,$row['ItemID'] 不同于 $item['itemid']

这就是您没有显示图像的原因。

因此,更正以下内容:

$Quantity = $row['Quantity'];
$ItemID = $row['ItemID'];
$ColorID = $row['ColorID'];

收件人:

$Quantity = $row['quantity'];
$ItemID = $row['itemid'];
$ColorID = $row['colorid'];

关于php - SQL打印表不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47790136/

相关文章:

php - Laravel-fopen : failed to open stream: Permission denied

html - 移动平台网站有水平滚动条,如何去掉?

javascript - 我的谷歌地图 DIV 位于其他所有内容之上 - 不明白为什么

php - 覆盖 Laravel 5.1 中的配置变量

php - 网站-即使pass1和pass2之间有错误,用户也可以编辑密码

php - Google Tag Manager PHP API 中 dataLayer.push 的等价物

html - 在 VIM 中剪切或抽出整个标签

mysql - 用于设置团队日程的数据库设计

java - 使用 Spring JPA 查询从序列中获取 nextval

SQL Server 数据库大小 - 为什么这么大?