<?php
$connection = mysql_connect ("localhost","root","") or die ('Connection Error');
mysql_select_db ("streamurl", $connection);
$sql = "SELECT * FROM `url`";
$raw = mysql_query($sql, $connection);
while ($show = mysql_fetch_array($raw)){
echo "<audio controls=yes autoplay=yes src=" . $show['URL'] . " </audio>";
}
?>
首先,我是php和mysql的新手。
在我的数据库中,我有2个流式音频链接,我已经在音频标签中回显了这些结果,如上面的代码所示。但结果只显示在1个音频标签中。但我想显示所有可用的链接,以便在单独的音频标签中回显。所以一点帮助将不胜感激。
答案 0 :(得分:1)
使用以下代码替换您的代码,您就完成了错过结束音频标记
<?php
$connection = mysql_connect ("localhost","root","") or die ('Connection Error');
mysql_select_db ("streamurl", $connection);
$sql = "SELECT * FROM `url`";
$raw = mysql_query($sql, $connection);
while ($show = mysql_fetch_array($raw)){
echo "<audio controls=yes autoplay=yes src=" . $show['URL'] . " ></audio>";
}
?>
答案 1 :(得分:0)
您忘记关闭代码。试试吧:
<?php
$connection = mysql_connect ("localhost","root","") or die ('Connection Error');
mysql_select_db ("streamurl", $connection);
$sql = "SELECT * FROM `url`";
$raw = mysql_query($sql, $connection);
while ($show = mysql_fetch_array($raw)){
echo "<audio controls=yes autoplay=yes src=\"{$show['URL']}\"></audio>";
}
?>
我把src属性引用为weel。
答案 2 :(得分:0)
试试这个
<?php
$connection = mysql_connect("localhost","root","") or die ('Connection Error');
mysql_select_db("streamurl", $connection);
$sql = "SELECT * FROM url";
$raw = mysql_query($sql);
while ($show = mysql_fetch_array($raw))
{?>
<audio controls=yes autoplay=yes src="<?php echo $show['URL']; ?>"></audio>
<?php
}?>
答案 3 :(得分:0)
这是我们编码竞赛的起点。
<?php
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("Database") or die(mysql_error());
$query=mysql_query("select `URL` form `url`") or die(mysql_error());
while($row=mysql_fetch_array($query)){
echo '<audio controls=yes autoplay=yes src="'.$show['URL'].'"></audio>';
}
?>
谢谢你
答案 4 :(得分:0)
我可以建议开始使用MySQLi或PDO_MYSQL而不是MySQL扩展,因为该扩展名已弃用。所以在MySQLi中类似的东西是: - http://php.net/manual/es/mysqli.query.php
<?php
$connection = new mysqli("localhost", "root", "", "streamurl");
if (mysqli_connect_errno()) {
echo("Connection Error: %s\n", mysqli_connect_error());
exit();
}
/***************start query****************/
if ($result = $connection->query("SELECT * FROM `url`;", MYSQLI_USE_RESULT)) {
while ($show = $result->fetch_assoc()) {
echo "<audio controls='yes' autoplay='yes' src='" . $show['URL'] . "'></audio>";
}
$result->close();
}
/***************end query****************/
$connection->close();
?>
为了在where子句中使用一些参数,您只需要更改查询部分: - http://php.net//manual/en/mysqli.prepare.php
/***************start query****************/
$param = "movie"; //any parameter for where clause
if ($stmt = $connection->prepare("SELECT * FROM `url` WHERE param = ?;")) {
/* bind parameters for markers */
$stmt->bind_param("s", $param);
/* execute query */
$stmt->execute();
$result = $stmt->get_result();
while ($show = $result->fetch_assoc()) {
echo "<audio controls='yes' autoplay='yes' src='" . $show['URL'] . "'></audio>";
}
$stmt->close();
}
/***************end query****************/