$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;
my rows contain anchor tags like this:
<a href="http://www.google.com">google</a>
But when this code runs, it only displays this in the browser:
google
Link does not work. Why?
=========
Here's the code that's outputting the code:
<?php require_once('add.php'); ?>
<p><?php echo $row; ?></p>
========= I've even tried doing this for testing purposes:
echo htmlspecialchars($row);
And it displays the raw anchor tags! Like this in the browser:
<a href="http://www.google.com">google</a>
++++++++++++++++++++++++
EDIT!!!!!
I looked at the outputted html in the browser through Chrome's dev tools and the slashes are missing in the link!!! WHY?
答案 0 :(得分:0)
在google.com之前加上 http:// :
<a href="http://www.google.com">google</a>
更新了查询:
选择链接时,您只需将http://连接到您的链接,如下所示:
SELECT concat('http://',link) as link FROM `links1` WHERE id=" . $row_id
答案 1 :(得分:0)
事实证明问题在于被提取的列包含ENTIRE锚链接。一旦我们将数据库更改为在一列中包含URL,并在另一列中包含链接名称,它就会起作用!
不确定原因......从列中提取整个锚链接可能是一个安全问题。