小编Kik*_*iki的帖子

MYSQL 缺少第一行数据

我编写了一个 PHP 脚本,其中返回餐厅名称、地址、电话号码、营业时间表和自定义菜单的链接。但是,即使数据库中有周一的条目,当我在 mysqli_fetch_assoc 中执行 while 循环时,它也不会显示。这是我的代码:

<?php
session_start();
$con=mysqli_connect("root","");
$rest_id2=$_GET['id'];
$rest_id=(int)$rest_id2;
var_dump($rest_id);
$sql="SELECT * FROM restaurant WHERE restaurant_id='".$rest_id."'";
$result=mysqli_query($con,$sql);
$rows=mysqli_fetch_assoc($result);
echo '<strong>'. "Restaurant name:". '</strong><br><br>';
echo $rows['restaurant_name'];
echo "<br><br>";
echo "<strong>Address: </strong><br><br>";
echo $rows['address_1']." ".$rows['address_2']." ". $rows['city']. ", ". 
$rows['state']. " ". $rows['zip']. "<br><br>";
echo '<strong>'. "Phone number:". '</strong><br><br>';
echo $rows['phone_number']. "<br><br>";
//hours table
$sql2="SELECT * from hours WHERE restaurant_id='".$rest_id."'";
$result2=mysqli_query($con,$sql2);
$row=mysqli_fetch_assoc($result2);
echo "<table border='1' cellpadding='10'><tr><th>Open or Closed</th> . 
<th>Day</th><th>Start Time</th><th>End Time</th></tr>";
$num_rows=mysqli_num_rows($result2);
// var_dump($num_rows);
while($row=mysqli_fetch_assoc($result2)){
    // var_dump($rows);
    if …
Run Code Online (Sandbox Code Playgroud)

php mysql mysqli associative-array fetch

1
推荐指数
1
解决办法
2170
查看次数

标签 统计

associative-array ×1

fetch ×1

mysql ×1

mysqli ×1

php ×1