不打印ID,而是打印'阵列&#39 ;?

时间:2014-04-20 01:51:18

标签: php mysql arrays function output

在我的代码中,它应该为通向相应页面的每个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 />";
}
?>

1 个答案:

答案 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起已弃用,将来会被删除。相反,应使用MySQLiPDO_MySQL扩展名的准备好的语句来抵御SQL注入攻击!