0

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

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

this. or read the big red warning here php.net/manual/en/function.mysql-fetch-array.php and use PDO
1

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:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.