在 table 中将两个 href 显示到单独的列中
Displaying two hrefs into separate columns in a table
我遇到了一个难以解决的问题。我有一个显示视频教程的系统。我下面的代码将视频名称 (eNISATQuestion) 和视频 (eNISATVideo) 的 link 作为一个 href 显示。
我想添加另一列以显示到 link 具有与以下部分类似布局的评级页面。
<tr>
<td>
<a href='{$row['eNISATVideo']}'>{$row['eNISATQuestion']}</a>
</td>
</tr>
具有值 (eNISATRateRef) 和 (eNISATRating)。
提前致谢
<?php
session_start();
include_once 'dbconnect.php';
if (!isset($_SESSION['user'])) header("Location: index.php");
$res = mysql_query("SELECT * FROM users WHERE user_id=".$_SESSION['user']);
$userRow = mysql_fetch_array( $res );
$userID = $_SESSION['user'];
$query = "SELECT eNISATQuestion, eNISATVideo, eNISATRateRef, eNISATRating FROM enisatquestion INNER JOIN enisatanswer WHERE
enisatanswer.eNISATID = enisatquestion.eNISATID AND user_id =
$userID AND eNISAT_watch = 1";
$result = mysql_query($query);
/* A default message if the query fails or there are no records */
$enisatquestion='<h2>Sorry, there are no records</h2>';
if($result) {/* if there is a recordset, proceed and generate html table */
$enisatquestion = "<table >";
while ($row = mysql_fetch_assoc($result)) {
**$enisatquestion .= "<tr><td><a href='{$row['eNISATVideo']}'>{$row['eNISATQuestion']}</a></td></tr>";**
}
$enisatquestion .= "</table>";
}
?>
<!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="home.php?home">Return to Homepage</a> <a
href="logout.php?logout">Sign Out</a>
</div>
</div>
<br>
<br>
<br>
<br>
<p align="center"><img src="title.jpeg" width="400"height="100" alt="title.jpeg">
<br>
<br>
<center>
<h2>Click on the each link to open your tutorial in Windows Media Player<h2>
<br>
<?php
/* output the html table here, below your header */
echo $enisatquestion;
/* If the query failed then the default gets displayed */
?>
</div>
</body>
</html>
只需添加另一个 td
元素并添加您从数据库中获取的新数据。
**$enisatquestion .= "
<tr>
<td><a href='{$row['eNISATVideo']}'>{$row['eNISATQuestion']}</a></td>
<td><a href='{$row['eNISATRateRef']}'>{$row['eNISATRating']}</a></td>
</tr>";**
如果这行代码...
<a href='{$row['eNISATVideo']}'>{$row['eNISATQuestion']}</a>
...与您使用的代码完全一致 copy/paste,请注意双引号。
<a href="{$row['eNISATVideo']}">{$row['eNISATQuestion']}</a>