【发布时间】:2016-06-03 15:35:14
【问题描述】:
我正在创建一个网页,让我可以按县搜索位置。我正在尝试在我的基本主页上创建一个 href 链接,该链接将调用一个 Php 函数,然后显示我的 Sql 数据库中的结果。 不知道为什么,但是当我单击 href 链接时,主页只是空白,没有返回值。已经检查过代码和数据库,已经向几个朋友展示过,但不知道出了什么问题。任何帮助表示赞赏!
这是我的 index.php 主页代码(href 大约在一半以下)
<!DOCTYPE HTML>
<?php
include("includes/db.php");
include("getAntrim.php");
include("functions/functions.php");
?>
<html>
<head>
<link rel = "stylesheet" href="styles/styles.css" media = "all"/>
<title>Location Scout</title>
</head>
<body>
<!-- Main container starts -->
<div class ="main_wrapper">
<div id="form">
<form method="get" action="results.php" enctype="multipart/form-data">
<input type="text" name="user_query" placeholder="Search for location"?>
<input type="submit" name="search" value="search"/>
</form>
</div>
<div class ="content_wrapper">
<div id ="left_sidebar">
<div id="sidebar_title">Search by County</div>
<a href="getAntrim.php">Antrim</a><br></br>
<div id ="content_area">
<div id ="products_box">
<!-- THIS IS WHERE FETCHED DATABASE INFO WILL GO -->
<?php
getAntrim();
?>
</div>
</div>
</div>
<!-- Main container ENDS -->
</div>
</div>
</body>
</html>
这是我的 getAntrim.php 函数,它应该对 sql 数据库进行排序,然后返回声明的值。
<?php
include ("includes/db.php");
if (isset ($_GET['getAntrim'])) {
$get_loc_co = "select * from locations where county='Antrim'";
$run_loc_co = mysqli_query($db, $get_loc_co); //Gets data from db and presents on main page
$count = mysqli_num_rows($run_loc_co);
if ($count==0) {
echo "<h2>No locations found in this category.";
}//if
while ($row_loc_co=mysqli_fetch_array($run_loc_co)) {
//variable to store values
$loc_id = $row_locations['loc_id'];
$loc_name = $row_locations['loc_name'];
$town = $row_locations['town'];
$county = $row_locations['county'];
$productions = $row_locations['productions'];
$disabled = $row_locations['dis_access'];
$parking = $row_locations['parking'];
$visitor = $row_locations['vis_facs'];
$transport = $row_locations['public_trans'];
$cost = $row_locations['cost'];
$accom = $row_locations['accom'];
$latitude = $row_locations['latitude'];
$longitude = $row_locations['longitude'];
$description = $row_locations['loc_desc'];
$keyword = $row_locations['loc_keyword'];
$loc_image = $row_locations['loc_img'];
echo "
<div id= 'single_location'>
<h3>$loc_name</h3>
<img src = 'Admin_area/location_images/$loc_image' width='180' height = '180'/><br>
<p><b>Productions: $productions </b></p>
<p><b>Description: $description </b></p>
</div>
";
}//while
}//if
?>
我是第一次发帖,所以希望已经发布了这个好的!任何建议表示赞赏。
【问题讨论】:
-
您的代码不起作用,并且该错误很可能在某处的错误日志中找到(取决于 Web 服务器)。
-
您在此处覆盖
$run_loc_co变量while ($row_loc_co=mysqli_fetch_array($run_loc_co)) {将其更改为while ($row_locations=mysqli_fetch_array($run_loc_co)) { -
谢谢 cmorrissey。已经尝试过这个和下面的其他建议,现在提出了其他错误消息。在下面的新答案中粘贴了屏幕截图。