我有一个mySQL数据库,里面全是<a>标签,但链接不工作时,回声'


I've got a mySQL database full of <a> tags but the links are not working when echo'ing

$mydb = new wpdb('xxxxxx','xxxxx','xxxxx','localhost');
$max_id = $mydb->get_results("SELECT MAX(id) FROM `links1`");
$row_id = ceil((mt_rand() / mt_getrandmax()) * intval($max_id[0]->{"MAX(id)"}));
$row_pre = $mydb->get_results("SELECT link FROM `links1` WHERE id=" . $row_id);
$row = $row_pre[0]->link;

我的行包含锚标记,像这样:

<a href="http://www.google.com">google</a>

但是当这段代码运行时,它只在浏览器中显示以下内容:

 google

链接不起作用。为什么?

=========

下面是输出代码的代码:
<?php require_once('add.php'); ?>
            <p><?php echo $row; ?></p>

=========我甚至尝试过这样做的测试目的:

echo htmlspecialchars($row);

它显示原始锚标记!在浏览器中像这样:

<a href="http://www.google.com">google</a>

++++++++++++++++++++++++

编辑! !

我通过Chrome的开发工具查看浏览器中输出的html,链接中缺少斜杠!!为什么?

http://之前google.com

<a href="http://www.google.com">google</a>

更新查询:

选择链接时,您可以像下面这样将http://连接到您的链接:

SELECT concat('http://',link) as link FROM `links1` WHERE id=" . $row_id

问题在于被获取的列包含了整个锚链接。一旦我们将数据库更改为在一列中包含URL,在另一列中包含链接名称,它就工作了!

不知道为什么…也许从列中拉出整个锚链接是一个安全问题