PHP - 回声数组错误

时间:2017-07-21 10:52:05

标签: php sql arrays row echo



<?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'];

?>


  
&#13;
&#13;
&#13;

$ map,$ website,$ camping,$ hiking正在为链接提供404错误

$ parkimage未显示

$志愿者,$ donate,$ adjacent_parks正在回应&#39; Array&#39;在页面上

2 个答案:

答案 0 :(得分: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'];

?>

它会起作用。

答案 1 :(得分:-1)

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