如果其他数据大于 0,如何只输出数据

我目前正在从数据库中提取数据以部署到我的 HTML 页面上。我目前使用这个:


$sql = "SELECT item, count FROM user_inventory  WHERE identifier='".$steamhextoidfin."'";

    $result = $conn->query($sql);

    if ($result->num_rows > 0) {

      // output data of each row

      while($row = $result->fetch_assoc()) {

        echo  "<b>" . $row["item"]. "</b> " . $row[""]. "<br>";

      }

现在我想知道如果“计数”数据大于 0 (>0),它怎么可能只输出“项目”数据


PIPIONE
浏览 119回答 2
2回答

慕森卡

只需添加 where,这样您的代码将如下所示:$sql = "SELECT item, count FROM user_inventory&nbsp; WHERE identifier='".$steamhextoidfin."' AND count > 0";$result = $conn->query($sql);if ($result->num_rows > 0) {&nbsp; // output data of each row&nbsp; while($row = $result->fetch_assoc()) {&nbsp; &nbsp; echo&nbsp; "<b>" . $row["item"]. "</b> " . $row[""]. "<br>";&nbsp; }

繁星coding

你可以这样做:$sql = "SELECT item, count FROM user_inventory&nbsp; WHERE identifier='".$steamhextoidfin."' AND count > 0";您也可以对结果应用条件 - 如下所示if ($result->num_rows > 0) {&nbsp; &nbsp; &nbsp; // output data of each row&nbsp; &nbsp; &nbsp; while($row = $result->fetch_assoc()) {&nbsp; &nbsp; &nbsp; &nbsp; if($row["count"] > 0){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo&nbsp; "<b>" . $row["item"]. "</b> " . $row[""]. "<br>";&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP