Trying to make manageable output for Android to convert $output into JSONObjects. When I use the commented out bottom line, it receives the data in Android’s log just fine, but can’t convert JSONArray to JSONObject – thus the desire for a foreach loop to return each SQL row on its own. I can’t see any syntax issues, so I don’t know what PHP is complaining about – any ideas? Also, when I use the commented out print code, it returns proper results, so I know it’s no problem accessing the db.
Here’s the code:
<?php
define("DB_HOST", "localhost");
define("DB_USER", "*");
define("DB_PASSWORD", "*");
define("DB_DATABASE", "*");
mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_DATABASE);
$sql=mysql_query("select * from QUESTIONS where CATEGORY like 'elections'");
while($row=mysql_fetch_assoc($sql))
$output[]=$row;
foreach($output) {
echo $output;
}
mysql_close();
//print(json_encode($output));
?>
And here’s the error:
Parse error: syntax error, unexpected ')' in /home/frehud/public_html/android_api/getQuestions/index.php on line 13
you need to use
askeyword andassigneach value in a variable ($value here).Thenechothat variable.like below :