How to display database in php in order to show it in android app -
i have problem displaying mysql database running in xampp server, typed code connect doesn't show in php page didn't let me retrive data android app.
here's sql query:
create table `products` ( `id` varchar ( 32 ) not null, `description` varchar( 1024 ) not null , primary key (`id`), )engine = myisam ;
and php code :
<?php $username = 'root'; $password = ''; $dbname = 'qrtest'; $dbname = mysql_connect('localhost', $username, $password, $dbname) or die ("unable connect"); echo"connected succesfully!"; mysql_select_db("qrtest", $dbname) or die("can not connect database"); $result = mysql_query("select * products")or die("cannot select table"); while($row = mysql_fetch_assoc($result)) { output[] = $row; } print(json_encode($output)); echo"encoding done"; mysql_close($dbname); ?>
it should've shown me this:
[{"id":"coca cola 1l", "description":"qsfjqskdfjqksdffqsdfdf"},{"id":"ramy 1l","description":"azeazerzertzertzty"},....etc ]
but instead show messages:
connected succesfully!encoding done
so please need here.
you have typo, it's $output
, not output
. try following:
$output = array(); while($row = mysql_fetch_assoc($result)){ $output[] = $row; } print(json_encode($output));
your mysql statement invalid. think mean:
select * products 1
not
select * products
Comments
Post a Comment