我对php的了解非常有限,虽然我知道mysql函数已被折旧但是对于这个项目来说无关紧要。
我有一张表(enisatquestion),其中包含培训问题,以及存储在我的电脑上的14个视频的文件路径,我想使用localhost显示这些视频。
我的表结构和表中其中一行的示例如下:
列是:
eNISATID(自动递增)
eNISATQuestion(培训问题)
eNISATVideo(视频的文件路径)
行的一个例子:
1
你能登录吗?
http://localhost \ Tna \ eNISAT \ LoginTutorial.wmv
这是我的代码,我收到了错误;
mysql_fetch_assoc()期望在第20行的C:\ wamp \ www \ Tna \ eNISATVids.php中给出至少1个参数0
任何人都可以帮助我这个,我已经研究了很多方法来展示这个,但我正在努力,因为我以前从未使用过php中的视频。视频也是wmv格式。或者任何人都可以给我一个更合适的例子
非常感谢
<?php
session_start();
include_once 'dbconnect.php';
if(!isset($_SESSION['user']))
{
header("Location: index.php");
}
//maintain SESSION user_id
$res=mysql_query("SELECT * FROM users WHERE user_id=".$_SESSION['user']);
$userRow=mysql_fetch_array($res);
//Select video name and question
$query = "SELECT eNISATQuestion, eNISATVideo FROM enisatquestion";
$result = mysql_query($query);
if($result === FALSE) {
die(mysql_error()); // TODO: better error handling
}
$enisatquestion = "<table >";
while ( $row = mysql_fetch_assoc($result) ) {
$enisatquestion .= "<tr><td><a href='{$row['eNISATVideo']}'>{$row['eNISATQuestion']}</a></td></tr>";
}
$enisatquestion .= "</table>";
echo $enisatquestion;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome - <?php echo $userRow['username']; ?></title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div id="header">
<div id="left">
<label>NHSCT eNISAT Tutorials</label>
</div>
<div id="right">
<div id="content">
Welcome <?php echo $userRow['forename']; ?> <a href="logout.php?logout">Sign Out</a>
</div>
</div>
</div>
</body>
</html>
答案 0 :(得分:0)
答案很简单:
$query = "SELECT eNISATName, eNISATVideo FROM enisatquestion";
$result = mysql_query($query);
$enisatquestion = "<table>";
while ( $r = mysql_fetch_assoc($result) ) {
$enisatquestion .= "<tr><td><a href='{$r['eNISATVideo']}'>{$r['eNISATName']}</a></td></tr>";
}
$enisatquestion .= "</table>";
echo $enisatquestion;
?>
注意传递给mysql_fetch_assoc的新$ result变量。