Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

nisc wwwxxx, wwwxxx0cm, should producers of software-based services, such as atms, be held liable for economic injuries suffered when their systems fail?, wwwxxx0cm, www.webdp.net, Event 9 IIS log failed to write entry, wwwxxx jeffs, Catastrophic failure Unexpected method call sequence. 0x8000ffff (-2147418113)., ksh lock a file, [unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_DBC failed

Links

XODOX
Impressum

#1: Formatting output with json_encode

Posted on 2008-07-14 08:21:23 by Ron Piggott

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

Report this message

#2: Re: Formatting output with json_encode

Posted on 2008-07-14 11:30:38 by Evert Lammerts

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

Report this message