[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-db
Subject:    Re: [PHP-DB] Formatting output with json_encode
From:       "Evert Lammerts" <evert.lammerts () gmail ! com>
Date:       2008-07-14 9:30:38
Message-ID: 6f083dca0807140230t18a143c0l485f5c870204c5b5 () mail ! gmail ! com
[Download RAW message or body]

Check out http://www.json.org/ for JSON structures.

In javascript an Array object is a special implementation of the
Object object (like all objects other than Object) - an Array object
can only have numerical indices, an Object object can have textual
indices too. If you json_encode a php array with textual indices it
translates to {...} - a javascript Object object. If you json_encode a
php array with numerical indices it translates to [...] - a javascript
Array object.

It seems to me that what you're using is mysql_fetch_array
(http://nl3.php.net/manual/en/function.mysql-fetch-array.php) with
either no result_type parameter set, or result_type set to MYSQL_BOTH.
If you want a javascript Array object, use either
mysql_fetch_array($result, MYSQL_NUM) or mysql_fetch_row($result). If
you want a javascript Object object, use either
mysql_fetch_array($result, MYSQL_ASSOC) or mysql_fecth_assoc($result).

Evert

On Mon, Jul 14, 2008 at 8:21 AM, Ron Piggott <ron.php@actsministries.org> wrote:
> I am using json_encode to output the results of a mySQL query which is
> part of a jquery & ajax.
>
> $result = json_encode($array);
> echo $result;
>
> The output on my screen is:
>
> {0:"John 14:27","verse_reference":"John 14:27"}
>
> How do I format json_encode output?  I would like
>
> John 14:27
>
> to be what is displayed.
>
> Ron
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic