SQL / PHP - 空白结果页面链接

时间:2017-01-19 20:41:36

标签: php sql

(我不再得到一个解析错误,只是我的标题和导航栏的空白apge-所以请注意它不是重复的帖子)

我有以下代码,它将添加指向详细信息页面的链接。我只是不确定我需要添加到详细信息页面以回应“名称”,我感到困惑,非常感谢我能得到的任何帮助。目前,当我点击搜索结果中的链接时,我只是一个空白的年龄。

的search.php

<?php

$page='search';
include('header.php');
include ('navbar.php');
echo "<br>";
include ('connect.php');



if (isset ($_POST['search'])) { //the 'search' refers to the 'search' name=search on the index page and makes does something when the search is pushed.
$search = $_POST['search'];
$search = "%" . $search . "%"; // MySQL wildcard % either side of search to get partially matching results

// No wildcard if you want results to match fully
} else {

header ('location: index.php');

}



$stmt = $conn->prepare("SELECT * FROM test_db WHERE name LIKE :name ORDER BY name ASC"); // Use = instead of LIKE for full matching
$stmt->bindParam(':name', $search);
$stmt->execute();
$count = $stmt->rowCount(); // Added to count no. of results returned


if ($count >= 1) { // Only displays results if $count is 1 or more

echo "<div class='results_found'>";
echo $count;
echo " results found<br>";
echo "</div>";

while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {

echo "<div class='results'>";
echo "<div class='result_name'>";
echo "<b>Whisky Name:</b><br>";
echo "<a href='details.php?id={$row['lot_id']}' >{$row['name']}</a>;";
echo "</div>";
echo "</div>";
}

} else {
echo " Sorry no records were found";
}

?>

Details.php

<?php

$page='details';
include('header.php');
include ('navbar.php');
include ('connect.php');

if (isset($_GET['lot_id'])) {

    echo $row['name'];

?>
</html>

1 个答案:

答案 0 :(得分:0)

确保检查是否设置了GET变量:就像

一样简单
if (isset($_GET['lot_id'])) {
  // DO something...
}

http://php.net/manual/en/function.isset.php