hyper link 显示在 table 之外
hyper link showing outside of table
我正在尝试按照下面的屏幕截图显示 table。
Screen Shot
目标是将 'folder' 图像作为可点击的 link 从 MySql table 获取 link 数据。
然而,当我尝试这样做(一步一步)时,hyperlinks 位于 table 之外。当我在以下内容周围添加标签时
echo '<a href="'.$row['file'].'">'.$row['file'].'</a>' ;
像这样
echo "<td>" '<a href="'.$row['file'].'">'.$row['file'].'</a>' "</td>";
后续 PHP 页面将不会加载
// Attempt select query execution
$sql = "SELECT * FROM versioncontrol";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table class='table table-bordered table-striped'>";
echo "<thead>";
echo "<tr>";
echo "<th>Image Link</th>";
echo "<th>Manual Link File</th>";
echo "<th>Operating Procedure ID</th>";
echo "<th>Operating Procedure Name</th>";
echo "<th>Operating Procedure Version</th>";
echo "<th>Upload Date and Time</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>
<a href=\"sopversioncontrolKL001.php" . $record['images'] . "\" >
<img src=\"images/document.jpg" . $record['images'] . "\" height=\"30\"
/></a></td>";
echo '<a href="'.$row['file'].'">'.$row['file'].'</a>' ;
echo "<td>" . $row['SOP_ID'] . "</td>";
echo "<td>" . $row['SOP_Name'] . "</td>";
echo "<td>" . $row['SOP_Version'] . "</td>";
echo "<td>" . $row['reg_date'] . "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
// Free result set
mysqli_free_result($result);
} else{
echo "<p class='lead'><em>No records were found.</em></p>";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
echo "<td>" '<a href="'.$row['file'].'">'.$row['file'].'</a>' "</td>";
The subsequent PHP page will not load
嗯,不会的。这是一个语法错误。
在 echo "<td>"
之后,您需要有一个 ;
或一个运算符。
您不能 运行 直接进入另一个字符串文字。
将 <td>
和 </td>
放入您已有的字符串文字中。
echo '<td><a href="'.$row['file'].'">'.$row['file'].'</a></td>';
更好的是,去掉一大堆 echo
语句,只输出 HTML.
?>
...
<td><a href="<?php echo $row['file']; ?>"><?php echo $row['file']; ?></a></td>
...
<?php
(您可能也应该使用 htmlspecialchars
来保护自己免受存储型 XSS 攻击)。
我正在尝试按照下面的屏幕截图显示 table。
Screen Shot
目标是将 'folder' 图像作为可点击的 link 从 MySql table 获取 link 数据。 然而,当我尝试这样做(一步一步)时,hyperlinks 位于 table 之外。当我在以下内容周围添加标签时
echo '<a href="'.$row['file'].'">'.$row['file'].'</a>' ;
像这样
echo "<td>" '<a href="'.$row['file'].'">'.$row['file'].'</a>' "</td>";
后续 PHP 页面将不会加载
// Attempt select query execution
$sql = "SELECT * FROM versioncontrol";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table class='table table-bordered table-striped'>";
echo "<thead>";
echo "<tr>";
echo "<th>Image Link</th>";
echo "<th>Manual Link File</th>";
echo "<th>Operating Procedure ID</th>";
echo "<th>Operating Procedure Name</th>";
echo "<th>Operating Procedure Version</th>";
echo "<th>Upload Date and Time</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>
<a href=\"sopversioncontrolKL001.php" . $record['images'] . "\" >
<img src=\"images/document.jpg" . $record['images'] . "\" height=\"30\"
/></a></td>";
echo '<a href="'.$row['file'].'">'.$row['file'].'</a>' ;
echo "<td>" . $row['SOP_ID'] . "</td>";
echo "<td>" . $row['SOP_Name'] . "</td>";
echo "<td>" . $row['SOP_Version'] . "</td>";
echo "<td>" . $row['reg_date'] . "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
// Free result set
mysqli_free_result($result);
} else{
echo "<p class='lead'><em>No records were found.</em></p>";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
echo "<td>" '<a href="'.$row['file'].'">'.$row['file'].'</a>' "</td>";
The subsequent PHP page will not load
嗯,不会的。这是一个语法错误。
在 echo "<td>"
之后,您需要有一个 ;
或一个运算符。
您不能 运行 直接进入另一个字符串文字。
将 <td>
和 </td>
放入您已有的字符串文字中。
echo '<td><a href="'.$row['file'].'">'.$row['file'].'</a></td>';
更好的是,去掉一大堆 echo
语句,只输出 HTML.
?>
...
<td><a href="<?php echo $row['file']; ?>"><?php echo $row['file']; ?></a></td>
...
<?php
(您可能也应该使用 htmlspecialchars
来保护自己免受存储型 XSS 攻击)。