已关闭。此问题需要details or clarity。当前不接受答案。
**想要改进此问题?**添加详细信息并通过editing this post阐明问题。
昨天关门了。
Improve this question
Page 1:将所有影片作为链接项查看。
<?php
session_start();
require_once 'db_connectie.php';
function alleFilms() {
$db = maakVerbinding();
$data = $db->query('select movie_id, title from Movie Order by title');
$film= '<ol>';
foreach ($data as $rij) {
$movie_id = $rij['movie_id'];
$title = $rij['title'];
$film .= '<li>';
$film .= "<a href=\"moviePagina.php?movieId=". $rij['movie_id'] ."\">";
$film .= $title;
$film .= '</a>';
$film .= '</li>';
$film .= '<br>';
}
$film .= '</ol>';
return $film;
}
?>
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Movies</title>
</head>
<body>
<?php require_once 'header.php'; ?>
<main>
<?= alleFilms(); ?>
</main>
<?php require_once 'footer.php'; ?>
</body>
</html>
Page 2查看选中项目的详细信息。
<?php
session_start();
if(empty($_SESSION['customer_mail_address'])){
echo "eerst inloggen";
//naarInloggenPagina
exit();
}
function movie(){
$movie_id = $_GET['movie_id'];
$db = maakVerbinding();
$sql = "select movie_id, title, duration from Movie where movie_id = '";
$sql .= $movie_id;
$sql .= "' Order by title";
$data = $db->query($sql);
$movie = "<table>";
foreach ($data as $rij) {
$movie_id = $rij['movie_id'];
$title = $rij['title'];
$duration = $rij['duration'];
$movie .= "<tr>
<th>movie_id </th>
<th>title </th>
<th>duration </th>
</tr>";
$movie .= "<tr>
<td>$movie_id </td>
<td>$title </td>
<td>$duration </td>
</tr>";
}
$movie .= "</table>";
return $movie;
}
?>
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= $_SESSION['title']; ?> movie</title>
</head>
<body>
<?php require_once 'header.php'; ?>
<main>
<?= movie(); ?>
</main>
<?php require_once 'footer.php'; ?>
</body>
</html>
我尝试将$movie_id从第一页发送到另一页,但没有成功。我收到此错误“未定义的变量$movie_id”。我想在第二页的SQL查询中使用$movie_id来查看选定的电影。
1条答案
按热度按时间wxclj1h51#
正如Adyson所提到的,您需要以url参数的形式将title传递给url,如代码所示。
如果要使用电影标题在第二页上查找电影,则应该考虑为每个电影使用唯一ID,并将该ID传递到第二页,然后使用它来进行查找。