gpt4 book ai didi

php - 使用 MySql 使用特定列填充 html 表

转载 作者:行者123 更新时间:2023-11-30 00:56:52 25 4
gpt4 key购买 nike

本质上,我正在创建一个具有 7 种电影类型的电影订购系统,并且我希望每个电影选项卡都根据类型进行填充。此时我什至无法让 table 出现。谁能帮帮我吗?

    <div id="content">
<table>
<tr><th>Name</th> <th>Genre</th> <th>Year</th> <th>Rating</th></tr>
<?php
//connect to database
$dbc = mysql_connect('localhost' , 'username' , 'password');
$test = mysql_select_db('movies', $dbc);

if ($test = mysql_select_db('movies', $dbc))//test
{
$query = "SELECT * FROM 'movies' WHERE 'genre' = 'Action'";

//call query
$result = mysql_query($query, $dbc);

while ($row = mysql_fetch_array($result))
{
?>

<tr>
<td><?php print $row['name']; ?></td>
<td><?php print $row['genre']; ?></td>
<td><?php print $row['year']; ?></td>
<td><?php print $row['rating'];?></td>
</tr>
<table>

<?php

}//close the while loop

}//close the if statement

mysql_close($dbc);

?>

最佳答案

首先不要使用mysql,因为安全问题,以后PHP将不再支持它。了解此内容 http://php.net/manual/en/function.mysql-connect.php .

尝试使用 PDO 或 mysqli,例如:

$con=mysqli_connect("example.com","peter","abc123","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM 'movies' WHERE 'genre' = 'Action'");

while($row = mysqli_fetch_array($result))
{
echo $row['name'];
echo "<br>";
}

mysqli_close($con);

关于php - 使用 MySql 使用特定列填充 html 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20479513/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com