我有数据库“媒体”与表格“视频”
CREATE TABLE IF NOT EXISTS `video` (
`id` int(12) NOT NULL AUTO_INCREMENT,
`title` varchar(25) NOT NULL,
`link` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
表视频包含3个字段: 的 ID, 标题, 链接(包含iframe和视频链接)。
我想显示mysql表中的所有视频,但只显示第一个视频。
<?php
$con=mysqli_connect("localhost","user","password","database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM video");
while($row = mysqli_fetch_array($result))
{
$id = $row["id"];
$videoiframe = $row["link"];
}
echo "{$videoiframe}";
?>
答案 0 :(得分:0)
循环覆盖id and videoiframe
的值。您需要定义一个数组并将值存储为
$array=array();// define array
while( $row = mysqli_fetch_array($result)){
$array[] = $row; // Inside while loop
}
print_r($array);// get all value
更新
while($row = mysqli_fetch_array($result))
{
$user.=$row['link']."</br>";
}
echo $user;