【问题标题】:hyper link showing outside of table显示在表格外的超链接
【发布时间】:2021-07-20 18:23:18
【问题描述】:

我正在尝试按照下面的屏幕截图显示一个表格。

Screen Shot

目标是将“文件夹”图像作为可点击链接从 MySql 表中获取链接数据。 但是,当我尝试执行此操作(逐步)时,超链接位于表格之外。当我在以下内容周围添加标签时

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

【问题讨论】:

  • 将它放入 &lt;td&gt;
  • @brombeer — 这就是他们想要做的事情

标签: php mysql hyperlink


【解决方案1】:
echo "<td>" '<a href="'.$row['file'].'">'.$row['file'].'</a>' "</td>";

后面的PHP页面不会加载

嗯,不会的。这是语法错误。

在echo "&lt;td&gt;" 之后,您需要有; 或运算符。

你不能直接碰到另一个字符串字面量。

将&lt;td&gt; 和&lt;/td&gt; 放入已有的字符串文字中。

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 攻击)。

【讨论】:

  • 谢谢您,先生,很抱歉成为新手。您的解决方案现在非常有意义。而不是显示地址我如何显示图像,即而不是... echo ''.$row['file']. ''; ...显示图像'document.jpg,其中href被图像替换... echo " "; ...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-14
  • 2011-09-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多