在 php 中创建自定义页面
Create custom pages in php
我目前正在php开发一个电影目录,该站点已连接到我的数据库并显示数据
在 table 中,"title" 部分的元素有一个 link(可点击),我希望它将这些 link 引用到页面电影。php/Aname = "idOfTheMovie" (link Personalized) 显示海报,导演等数据库信息...
Php index.php 代码:
<?php
$con=mysqli_connect("localhost","root","root","movie");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM allmovie");
echo "
<center>
<table border='1'>
<tr>
<th>Title</th>
<th>Director</th>
<th>My score</th>
<th>imdb note</th>
<th>Time</th>
<th>Year</th>
<th>Type</th>
<th>Poster link</th>
</tr>
</center>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td><a target='_self' href='movie.php?Aname=" . $row['id'] ."'>". $row['title'] . "</a>";"" . $row['title'] . "</td>";
echo "<td>" . $row['director'] . "</td>";
echo "<td>" . $row['score'] . "</td>";
echo "<td>" . $row['imdb_score'] . "</td>";
echo "<td>" . $row['time'] . "</td>";
echo "<td>" . $row['year'] . "</td>";
echo "<td>" . $row['type'] . "</td>";
echo "<td>" . $row['poster_link'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
我为 movie.php 页面尝试了很多代码,但我没有找到合适的代码
谢谢:)
您可以使用 php $_GET[] 全局变量来实现您的目标。
示例:movie.php
<?php
$id = $_GET['Aname'];
if (empty($id)) {
echo "an error occured";
} else {
$code = 'SELECT * FROM allmovie where id = "$id"';
$data = mysqli_query($code);
while ($row = mysqli_fetch_array($data)) {
//some codes
}
}
?>
希望对您有所帮助。如果我犯了错误,请纠正我。
我目前正在php开发一个电影目录,该站点已连接到我的数据库并显示数据 在 table 中,"title" 部分的元素有一个 link(可点击),我希望它将这些 link 引用到页面电影。php/Aname = "idOfTheMovie" (link Personalized) 显示海报,导演等数据库信息...
Php index.php 代码:
<?php
$con=mysqli_connect("localhost","root","root","movie");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM allmovie");
echo "
<center>
<table border='1'>
<tr>
<th>Title</th>
<th>Director</th>
<th>My score</th>
<th>imdb note</th>
<th>Time</th>
<th>Year</th>
<th>Type</th>
<th>Poster link</th>
</tr>
</center>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td><a target='_self' href='movie.php?Aname=" . $row['id'] ."'>". $row['title'] . "</a>";"" . $row['title'] . "</td>";
echo "<td>" . $row['director'] . "</td>";
echo "<td>" . $row['score'] . "</td>";
echo "<td>" . $row['imdb_score'] . "</td>";
echo "<td>" . $row['time'] . "</td>";
echo "<td>" . $row['year'] . "</td>";
echo "<td>" . $row['type'] . "</td>";
echo "<td>" . $row['poster_link'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
我为 movie.php 页面尝试了很多代码,但我没有找到合适的代码 谢谢:)
您可以使用 php $_GET[] 全局变量来实现您的目标。
示例:movie.php
<?php
$id = $_GET['Aname'];
if (empty($id)) {
echo "an error occured";
} else {
$code = 'SELECT * FROM allmovie where id = "$id"';
$data = mysqli_query($code);
while ($row = mysqli_fetch_array($data)) {
//some codes
}
}
?>
希望对您有所帮助。如果我犯了错误,请纠正我。