Reputation: 997
I am displaying data from database using PHP. I am using JSON. but during result, I got unwanted array. This is sample:
while($row = mysql_fetch_array($result))
{
echo "<pre>"; print_r($row); echo "</pre>";
//$output[]=$row;
}
Output:
Array
(
[0] => Ravi Ad
[title] => Ravi Ad
)
Here I saw , a extra column is displaying name [0]. i hate it and making problem in parsing . May any once can remove it ? i am trying this result:-
Array
(
[title] => Ravi Ad
)
thank you
Upvotes: 0
Views: 193
Reputation: 2265
use
mysql_fetch_assoc($result)
instead of mysql_fetch_array($result)
This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:
Upvotes: 1
Reputation: 32830
try mysql_fetch_assoc
while($row = mysql_fetch_assoc($result))
{
echo "<pre>"; print_r($row); echo "</pre>";
//$output[]=$row;
}
NOTE : mysql_* is deprectaed in new version of php use mysqli or PDO
ref: http://php.net/manual/en/function.mysql-fetch-array.php
Upvotes: 1