将结果页面链接到详细信息页面

时间:2013-11-06 21:17:53

标签: javascript php jquery html mysql

这是我的结果页面,我需要帮助将每个餐馆链接到detail.php页面。

我正在一个网站上显示旧金山的所有餐厅的健康检查分数,地址和违规行为。

第一页是我的索引页面,它只是一个搜索栏,允许您输入餐馆的名称或关键字。这会导致我的results.php页面获取所有数据,并为您提供搜索匹配示例的列表。我遇到的问题是,从results.php页面我必须将它链接到我列出的每个餐馆的details.php。然后详细页面将显示他们的健康检查得分,地址和餐厅地图。

如何将餐馆链接到详细信息页面?

这是我的网站链接:http://jfol.io/j426/s13/mariana/a07/

  
<!doctype html>

<html lang="en">

<head>

<meta charset="utf-8">

<title>A07</title>

<link href='http://fonts.googleapis.com/css?family=Armata' rel='stylesheet' type='text/css'>

<link rel="stylesheet" href="css/style.css" />

</head>

<body>

<div id="left-nav">

<a href="index.php">Home</a>
<a href="results.php">Restaurants</a>
<a href="details.php">Violations</a>
<a href="#">Scores</a>

</div>

<div id="main">
<?php

// load query

$query = "

SELECT  businesses.business_id                AS    business_id,
                businesses.name               AS     name,
                inspections.score             AS    score,
                inspections.date              AS     date,     
                inspections.business_id

FROM             businesses

INNER JOIN      inspections

ON                      businesses.business_id = inspections.business_id

WHERE           businesses.name LIKE '%$business_name%'

ORDER BY         businesses.name ASC

LIMIT            $row_start, $pagination";

// output page header

echo "<h1> Restaurants </h1>";

// output query (debug)

 //echo "<i>Debug:</i> " . $query . "<p></p>";

// execute query

$result     = mysqli_query($db_connection,$query);

// grab count of records returned

$row_count  = mysqli_num_rows($result);

// output record count

echo "Displaying records " . ($row_start + 1) . " to " . ($row_start + $pagination) . " <p></p>";

// advance pagination counter

$row_start = $row_start + $pagination;

// output pagination link

echo ("<p></p><a href=\"results.php\">First page</a> | <a href=\"results.php?row_start=" . $row_start . "\">Next " . $pagination . " records</a><p></p>");

// create table tag

echo ("<table>\n\n");

echo ("<tr class=\"header\">\n<td>Business Name</td><td>Inspection Score</td><td>Inspection Date</td></tr>\n");

// create row counter

$current_row = 0;

// loop through returned records

while ($row = mysqli_fetch_array($result))

{

// set variables

    $business_id            =   $row["business_id"];
    $business_name          =   ucwords(strtolower($row["name"]));
    $inspection_score       =   $row["score"];

    //$address              =   $row["address"];

    $violation_date         =   date("n/j/Y",strtotime($row["date"]));

    $inspection_date            =   date("n/j/Y",strtotime($row["date"]));

// output to screen

// echo($business_name . " / " . $violation_description . " / " . $violation_date . "<br />");

if ($current_row % 2 == 0)

{

$shading = "alternate ";

}

else

{

$shading = "";

}

echo ("<tr class=\"$shading\">\n\n");

echo("<td>\n\n" . $business_name . "</td>\n\n<td>\n\n" . $inspection_score . "</td>\n\n<td>\n\n" . $inspection_date . "</td>\n\n" );

echo ("</tr>\n\n");

$current_row++;

}

echo ("</table>\n\n");

// output pagination link

echo ("<p></p><a href=\"results.php\">First page</a> | <a href=\"results.php?row_start=" . $row_start . "\">Next " . $pagination . " records</a><p></p>");

?>`enter code here`

</div>
</body>
</html>

2 个答案:

答案 0 :(得分:1)

我假设每个餐馆的数据库都有一个id

您的结果页面会为每个

添加一个链接
<a herf="details.php?id=i23">the food shack</a>

on details.php使用id来查询db

$id = isset($_GET['id']) ? (int) $_GET['id'] : null;
SELECT * from foo where id=$id

答案 1 :(得分:1)

当您在结果页面上填充结果时,您很可能拥有每个餐厅的唯一记录ID。您需要将该ID添加到您生成的表中循环内的链接,如下所示。

<td><a href="/details.php?id=<?= $r['id'] ?><?= $r['name'] ?></a></td>