FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Json result
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Json result [message #175720] Sat, 22 October 2011 19:02 Go to next message
Sarah is currently offline  Sarah
Messages: 30
Registered: December 2010
Karma: 0
Member
Hi! I had a page for generate an XML file, now I'm trying to change it
for return JSON file

in $result I've my query

while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {

$data['locations'][] = $row;
}

Header('Content-type: application/json');
echo json_encode($data);
exit;


When I try to exevcute this page browser ask me to download the page
and if I insert

echo '----';
print_r($data['locations']);
print_r($data);
die;
Header('Content-type: application/json');
echo json_encode($data);
exit;


I show only '---'

Can you help me??

Thanks
Re: Json result [message #175722 is a reply to message #175720] Sat, 22 October 2011 19:39 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 10/22/2011 3:02 PM, Sarah wrote:
> Hi! I had a page for generate an XML file, now I'm trying to change it
> for return JSON file
>
> in $result I've my query
>
> while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
>
> $data['locations'][] = $row;
> }
>
> Header('Content-type: application/json');
> echo json_encode($data);
> exit;
>
>
> When I try to exevcute this page browser ask me to download the page
> and if I insert
>
> echo '----';
> print_r($data['locations']);
> print_r($data);
> die;
> Header('Content-type: application/json');
> echo json_encode($data);
> exit;
>
>
> I show only '---'
>
> Can you help me??
>
> Thanks

It would be normal for the browser to ask if you wanted to download the
file. The browser doesn't know how to handle a file of type
application/json.

As for your results - what do you see when you look at the page source?

Enable all errors and display them to see if you have any. In the
php.ini file on your development system, put:

error_reporting=E_ALL
display_errors=on

See if you get any errors (you should have this in your development
system anyway).

If you don't see any errors, your query just returned no data and the
page source just contains the '---', then your query is just returning
no data.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Json result [message #175726 is a reply to message #175722] Sat, 22 October 2011 21:16 Go to previous messageGo to next message
Sarah is currently offline  Sarah
Messages: 30
Registered: December 2010
Karma: 0
Member
You're right!!! I can show items in my PHP page!!

So:

1) why my print_r was not??

2) is it right to have a php file with json structure?? I need a json
file for allow an external app to import these values.... but can you
suggest my right way about extension of this file? And how to set this
right extension?

Thanks
Re: Json result [message #175728 is a reply to message #175726] Sat, 22 October 2011 21:22 Go to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 10/22/2011 5:16 PM, Sarah wrote:
> You're right!!! I can show items in my PHP page!!
>
> So:
>
> 1) why my print_r was not??
>
> 2) is it right to have a php file with json structure?? I need a json
> file for allow an external app to import these values.... but can you
> suggest my right way about extension of this file? And how to set this
> right extension?
>
> Thanks

Because your browser is trying to parse the page as html. Since it's
invalid html, the browser is just doing its best.

If this is a json file, then that is the correct type. But don't expect
your browser to be able to display non (x)html or xml. That's not what
they're made to do.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Import values reading from XML nodes
Next Topic: PHP Extension Namespaces
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 20:27:43 GMT 2024

Total time taken to generate the page: 0.02455 seconds