php - 来自 mysql db 的 url,在带有 php 的表中带有 <A> 标记

标签 php mysql

我找不到我想知道的问题,因为我已经编写了大部分代码,只需要这一小部分来工作,所以很难理解别人的问题。

这是不起作用的部分:

echo "<TD width='220px' style='padding:5px;'>" . "<a href='>" . $row['horselink'] ."'><strong>" . $row['name'] . "</strong></a></td>";

我希望 href 从 horselink 列收集数据,以便它链接名称。我尝试了几种方法,但就是无法正常工作。任何人都有好的提示或想法如何正确编写链接/url 部分,因为表格的其余部分工作得很好。

完整代码如下:

 <?php
                        include("conn.php"); //Databas koppling
                        mysql_set_charset("utf8");
                        $result = mysql_query("SELECT name, horselink, born, gender, discipline, breed, sire, dam FROM Horse WHERE horsetype = 'young' ORDER by born");
                        //Hämtar all information från kurser


                            echo "<table id='trhover' class='tableclassen' cellpadding='3' cellspacing='1'>";
                            echo "<TR class='trhead' style='text-transform:uppercase; background-color: #6e3f47;'>";
                            echo "<TD width='220px' style='padding:5px;'><strong>Name<strong></TD>";
                            echo "<TD width='60px' style='padding:5px;'><strong>Dob</strong></TD>";
                            echo "<TD width='90px' style='padding:5px;'><strong>Gender</strong></TD>";
                            echo "<TD width='110px' style='padding:5px;'><strong>Discipline</strong></TD>";
                            echo "<TD width='120px' style='padding:5px;'><strong>Breed</strong></TD>";
                            echo "<TD width='160px' style='padding:5px;'><strong>Sire</strong></TD>";
                            echo "<TD width='160px' style='padding:5px;'><strong>Dam</strong></TD>";
                            echo "</TR>";


                        while($row = mysql_fetch_array($result)) // Skriver ut all information i en tabell
                         {
                            echo "<TR>";
                            echo "<TD width='220px' style='padding:5px;'>" . "<a href='>" . $row['horselink'] ."'><strong>" . $row['name'] . "</strong></a></td>";
                            echo "<TD width='60px' style='padding:5px;'>" . $row['born'] . "</td>";
                            echo "<TD width='90px' style='padding:5px;'>" . $row['gender'] . "</td>";
                            echo "<TD width='110px' style='padding:5px;'>" . $row['discipline'] . "</td>";
                            echo "<TD width='120px' style='padding:5px;'>" . $row['breed'] . "</td>";
                            echo "<TD width='160px' style='padding:5px;'>" . $row['sire'] . "</td>";
                            echo "<TD width='160px' style='padding:5px;'>" . $row['dam'] . "</td>";
                            echo "</tr>";
                         }
                            echo "</table>";

                    ?>

最佳答案

这一行:

echo /* ... */ "<a href='>" . $row['horselink'] ."'><strong>" /* ... */;

有一个额外的 > 在里面。应该是:

echo /* ... */ "<a href='" . $row['horselink'] ."'><strong>" /* ... */;

:

  • 您应该使用已弃用的mysql 函数。使用 PDOmysqli .
  • 你应该用 htmlspecialchars() 转义你的输出.
  • 使用 <THEAD> 标记表格标题被认为是一种很好的做法和 <TH>元素。

关于php - 来自 mysql db 的 url,在带有 php 的表中带有 <A> 标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24588794/

相关文章:

javascript - 无法通过JQUERY传递PHP变量并将其插入到MYSQL中

php - Instagram API 无法找到有关私有(private)文件的信息

php - SwiftMailer 反射异常 : Class Egulias\EmailValidator\EmailValidator does not exist

mysql查询找到 "Not a friend"

mysql - 如何将ListBox项目分别插入到MySQL的不同行?

php - 使用 Square Connect ChargeResponse 对象时遇到问题

PHP:性能:splat 运算符或反射

c# - 如何使用 MySQL 查询将组合框的所有项目发送到 SQL DB

mysql - 从表中选择具有不同列值的行

php - php 的 mysql_real_escape_string() 的等效 javascript 代码是什么?