1

得到错误

注意:未定义变量:第 65 行 C:\xampp\htdocs\ipo\details.php 中的行。

我正在使用 php 和 sql。

<?php
    include 'header.php';
    include 'navbarmain.php';
    $count = 0;

    $PageID = (int) trim($_GET['id']);
    if($PageID == 0){
        //you can show error or redirect to other page
    }

    $mysqli = mysqli_query($connection,"SELECT * FROM products WHERE id='{$PageID}' LIMIT 1");
    foreach($mysqli as $row){
        $count++;
        if($count == 0) { // three items in a row
            $count = 0;
        }
    }

?>

<a href="#">
  <img class="media-object" src="<?php echo $row["filename"]; ?>" alt="...">
  <span class="nsbs">NSE / BSE</span>
</a>
4

1 回答 1

-1

您正在尝试在循环之外写入文件名。这可能是您的错误的原因。请尝试以下代码

<?php
    include 'header.php';
    include 'navbarmain.php';
    $count = 0;

    $PageID = (int) trim($_GET['id']);
    if($PageID == 0){
        //you can show error or redirect to other page
    }

    $mysqli = mysqli_query($connection,"SELECT * FROM products WHERE id='{$PageID}' LIMIT 1");
    foreach($mysqli as $row){
        $count++;
        if($count == 0) { // three items in a row
            $count = 0;
        }

    ?>
    <a href="#">
      <img class="media-object" src="<?php echo $row["filename"]; ?>" alt="...">
      <span class="nsbs">NSE / BSE</span>
    </a>

     <?php
    }

?>
于 2020-03-06T04:32:47.880 回答