将两个href显示在表中的单独列中

时间:2016-02-17 21:28:47

标签: php html css href

我遇到了一个我遇到困难的问题。我有一个显示视频教程的系统。我的代码显示视频名称(eNISATQuestion)和视频链接(eNISATVideo)作为一个href。

我想添加另一列以显示链接到评级页面,其布局与下面的部分类似。

<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']; ?>&nbsp;<a href="home.php?home">Return to Homepage</a>&nbsp;&nbsp;<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>

2 个答案:

答案 0 :(得分:2)

只需添加另一个td元素,然后添加从数据库中提取的新数据。

**$enisatquestion .= "
  <tr>
    <td><a href='{$row['eNISATVideo']}'>{$row['eNISATQuestion']}</a></td>
    <td><a href='{$row['eNISATRateRef']}'>{$row['eNISATRating']}</a></td>
  </tr>";**

答案 1 :(得分:1)

如果这行代码......

<a href='{$row['eNISATVideo']}'>{$row['eNISATQuestion']}</a>

...是您正在使用的代码的精确复制/粘贴,请注意双引号。

<a href="{$row['eNISATVideo']}">{$row['eNISATQuestion']}</a>