I am new to PHP... I have been trying to encode the values retrieved from a MySQL database in JSON and then display the results on a browser..
mysqlcn.php
mysql_connect("127.0.0.1","root","chetan");
mysql_select_db("db1");
$q=mysql_query("SELECT * FROM people WHERE birthyear>'".$_REQUEST['year']."'");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output,JSON_FORCE_OBJECT));
mysql_close();
When I try to run it in a browser using address http://localhost/mysqlcn.php, I get this:
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\froman\fcharset0
Times New Roman;}{\f1\fswiss\fcharset0 Arial;}} {\*\generator Msftedit
5.41.15.1507;}\viewkind4\uc1\pard\sb100\sa100\f0\fs24\par \par \f1\fs20\par
\par }
I am currently using WAMP server with PHP 5.3.0
SQL schema
CREATE TABLE people (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
name VARCHAR( 100 ) NOT NULL ,
sex BOOL NOT NULL DEFAULT '1',
birthyear INT NOT NULL)
Ryan McCue
1,65814 silver badges23 bronze badges
2 Answers 2
Your output appears to be RTF. Most likely, you have some code which is converting it from HTML to RTF.
answered Feb 26, 2011 at 7:14
Ryan McCue
1,65814 silver badges23 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
chetan
yup u were correct...i then wrote the program in notepad++ and saved it...on running the program apache server crashed....dont know why???
Why do you wish to use JSON to do the display of your database?
PHP can handle this on its own just fine, unless you have a specific reason.
answered Feb 26, 2011 at 4:59
lockdown
1,5065 gold badges16 silver badges34 bronze badges
1 Comment
chetan
actually i am developing an android application where the client retrieves the data from server...i will be parsing data using json...
lang-php
application/jsonheader when you're outputtingJSONto the page.header("application/json");followed by your json encoded data.