在我的代码中,它应该为通向相应页面的每个ID创建一个链接,但它会指向页面?ID = Array而不是?ID = ID
这是我的代码,您可以在此处查看:http://pirates-online-rewritten.com/testblog.php
<?php
include "connect.php";
$ids = mysql_query("SELECT ID FROM Blogs ORDER BY ID DESC LIMIT 10");
while($id=mysql_fetch_assoc($ids)){
echo "<a href='http://www.pirates-online-rewritten.com/blog.php?ID=", $id, "'>Test</a><br />";
}
?>
答案 0 :(得分:2)
应该是$id['ID']
而不是$id
喜欢这个..
<?php
include "connect.php";
$ids = mysql_query("SELECT ID FROM Blogs ORDER BY ID DESC LIMIT 10");
while($id=mysql_fetch_array($ids)){ //<--- Changed to fetch_array
echo "<a href='http://www.pirates-online-rewritten.com/blog.php?ID=", $id['ID'], "'>Test</a><br />";
}
此mysql_*
)扩展程序自PHP 5.5.0
起已弃用,将来会被删除。相反,应使用MySQLi
或PDO_MySQL
扩展名的准备好的语句来抵御SQL注入攻击!