【问题标题】:PHP - Echo Array errorPHP - 回声数组错误
【发布时间】:2017-07-21 10:52:04
【问题描述】:

<?php

if (isset($_GET['id']) && filter_var($_GET['id'], FILTER_VALIDATE_INT)) {
    $id=$_GET['id'];
}else{
  header('HTTP/1.0 404 Not Found');
  exit("<h1>Not Found</h1>\n<p>The submitted data is not valid.</p>");
}



$query = "SELECT * FROM all_parks WHERE id = $id";


$result = mysqli_query($conn, $query) or die ("Error querying database.");


$row = mysqli_fetch_array($result);
  $state = $row['state'];
  $type = $row['type'];
  $name = $row['name'];
  $short_intro = $row['short_intro'];
  $long_description = $row['long_description'];
  $parkimage = $row['image_url'];
  $allowed = $row['allowed'];
  $not_allowed = $row['not_allowed'];
  $warnings = $row['warnings'];
  $more_details = $row['more_details'];
  $neighboring_parks = ['neighboring_parks'];
  $website = ['website'];
  $camping = ['camping'];
  $hiking = ['hiking'];
  $volunteer = ['volunteer'];
  $map = ['google_map_location'];
  $telephone = ['telephone'];
  $email = ['email'];

?>


  

$map, $website, $camping, $hiking 给出链接的 404 错误

$parkimage 未显示

$volunteer, $donate, $neighboring_parks 在页面上呼应“数组”

【问题讨论】:

  • 请补充一些解释
  • 将 $row 添加到这个数组变量 $website = ['website']; $camping = ['露营']; $hiking = ['远足'];

标签: php sql arrays row echo


【解决方案1】:

你忘了写 $row ,使用这个代码-

<?php

if (isset($_GET['id']) && filter_var($_GET['id'], FILTER_VALIDATE_INT)) {
    $id=$_GET['id'];
}else{
  header('HTTP/1.0 404 Not Found');
  exit("<h1>Not Found</h1>\n<p>The submitted data is not valid.</p>");
}



$query = "SELECT * FROM all_parks WHERE id = $id";


$result = mysqli_query($conn, $query) or die ("Error querying database.");


$row = mysqli_fetch_array($result);
  $state = $row['state'];
  $type = $row['type'];
  $name = $row['name'];
  $short_intro = $row['short_intro'];
  $long_description = $row['long_description'];
  $parkimage = $row['image_url'];
  $allowed = $row['allowed'];
  $not_allowed = $row['not_allowed'];
  $warnings = $row['warnings'];
  $more_details = $row['more_details'];
  $neighboring_parks = $row['neighboring_parks'];
  $website = $row['website'];
  $camping = $row['camping'];
  $hiking = $row['hiking'];
  $volunteer = $row['volunteer'];
  $map = $row['google_map_location'];
  $telephone = $row['telephone'];
  $email = $row['email'];

?>

它会起作用的。

【讨论】:

    【解决方案2】:

    使用while ($row = mysqli_fetch_array($result)),它会起作用。

    【讨论】:

      猜你喜欢
      • 2012-01-01
      • 2012-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-09
      • 1970-01-01
      • 1970-01-01
      • 2018-09-22
      相关资源
      最近更新 更多