在php中创建自定义页面

时间:2017-01-13 17:12:00

标签: php movie

我目前正在php中开发一个电影目录,该网站已连接到我的数据库并显示数据 在表格中,“标题”部分的元素有一个链接(可点击),我希望它将这些链接引用到一个页面movie.php / Aname =“idOfTheMovie”(链接个性化),它显示数据库的信息像海报,导演......

index.php的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页面尝试了很多代码,但我找不到好处 谢谢:))

1 个答案:

答案 0 :(得分:0)

您可以使用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
    }
}
?>
希望它有所帮助。如果我弄错了,请纠正我。