Sam
Sam

Reputation: 85

Not printing the ID, rather printing 'Array'?

In my code, it should create a link for every ID leading to the corresponding page, but it leads to the page ?ID=Array instead of ?ID=ID

This is my code, you can view it here: 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 />";
}
?>

Upvotes: 1

Views: 44

Answers (1)

It should be $id['ID'] instead of $id

Like this..

<?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 />";
}

This (mysql_*) extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, Prepared Statements of MySQLi or PDO_MySQL extension should be used to ward off SQL Injection attacks !

Upvotes: 2

Related Questions