我有一个课程数据库,我可以按照我想要的方式返回课程。我无法确定如何超链接课程名称,以便我只能在新页面上显示该课程数据(full.php)。我想获取课程ID,并在full.php上使用它作为我的WHERE语句来显示其他字段。
以下是我的尝试:echo "<table>
<tr>
<th>Course ID</th>
<th>Course Name</th>
<th>Provider Type</th>
<th>Audience</th>
<th>Provider Track</th>
<th>Course Delivery</th>
</tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>" .$row['courseID'] . "</td>";
echo "<td> <p> <strong>Course Name:</strong><a href=Full.php?name='".$courseID."'>". $row['courseName'] ."</a> </p>
<p> <strong>Course Number:</strong>".$row['courseNumber']." </p
<p> ".$row['courseDescription'] . " </p>
<p> <strong>Course Length:</strong> " .$row['courseLength'] . " </p>
</td>";
echo "<td>" .$row['courseProviderType'] . "</td>";
echo "<td>" .$row['courseAudience'] . "</td>";
echo "<td>" .$row['courseTrack'] . "</td>";
echo "<td>" .$row['courseDelivery'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
答案 0 :(得分:0)
您忘记了链接上的$ row变量。 这是一个修复:
echo "<table>
<tr>
<th>Course ID</th>
<th>Course Name</th>
<th>Provider Type</th>
<th>Audience</th>
<th>Provider Track</th>
<th>Course Delivery</th>
</tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>" .$row['courseID'] . "</td>";
echo "<td> <p> <strong>Course Name:</strong><a href=Full.php?name='".$row['courseID']."'>". $row['courseName'] ."</a> </p>
<p> <strong>Course Number:</strong>".$row['courseNumber']." </p
<p> ".$row['courseDescription'] . " </p>
<p> <strong>Course Length:</strong> " .$row['courseLength'] . " </p>
</td>";
echo "<td>" .$row['courseProviderType'] . "</td>";
echo "<td>" .$row['courseAudience'] . "</td>";
echo "<td>" .$row['courseTrack'] . "</td>";
echo "<td>" .$row['courseDelivery'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
在第二页上,您可以使用全局$ _GET变量$_GET['name']
获取此值。
答案 1 :(得分:0)
我建议直接从数据库行传递课程ID:
<a href=Full.php?name='".$row['courseID']."'>". $row['courseName'] ."</a>
并且可能为了清晰起见而更改属性名称:
<a href=Full.php?courseID='".$row['courseID']."'>". $row['courseName'] ."</a>
答案 2 :(得分:0)
替换此代码
<a href=Full.php?name='".$row['courseID']."'>". $row['courseName'] ."</a>
并缺少标签
<p> <strong>Course Number:</strong>".$row['courseNumber']." </p>