使用fetch_all(MYSQLI_ASSOC)从echo语句中返回任何内容

时间:2018-03-29 04:46:26

标签: php mysql associative-array

任何人都可以看到任何明显的错误,为什么我无法从数据库中检索任何内容?

     <!DOCTYPE html>
     <html>
     <body>
     <?php
     //Grabbing from ? in url
     $query_string=$_SERVER['QUERY_STRING'];
     // Converting query_string to int for restaurant_id
     $rest_id=(int)$query_string;
     var_dump($rest_id);
     $con=mysqli_connect("","","", "");
     $sql="SELECT * from menu_item WHERE restaurant_id='".$rest_id."'";
     if($result = $con->query($sql)){
        if($count=$result->num_rows){
            echo '<p>', $count, '</p>';
        }
    } else {
    die($con->error);
    }
    $rows=$result->fetch_all(MYSQLI_ASSOC);

    foreach($rows as $row) {
        echo $row['category'], '<br>';
    }
    $mysqli->close();
    ?>
   <h1>You clicked a button</h1>
   <p>Yay!!!</p>

   </body>
   </html>

0 个答案:

没有答案