I'm wondering if it is possible to combine many queries into one array and return it. The problem is that some of those queries already are arrays...here's what I mean:
JS:
function getNews() {
$.getJSON(serviceURL + 'getmainnews.php', function(data) {
$('#fnews li').remove();
daily = data.items;
$.each(daily, function(index, mnews) {
//append the data to listview
});
});
Here is the php file with the queries:
<?php
include 'connect_to_mysql.php';
mysql_query("SET NAMES UTF8");
$day = mysql_query("SELECT * FROM basket_news WHERE topic='daily' ORDER BY id DESC LIMIT 1");
$daily = array();
while ($r = mysql_fetch_assoc($day)){
$daily[] = $r;
}
$sql = mysql_query("SELECT * FROM basket_news WHERE topic='' ORDER BY id DESC");
$mainnews = array();
while ($r = mysql_fetch_assoc($sql)){
$mainnews[] = $r;
}
?>
If I have more queries like this, how can I gather them together to be able to do something like:
echo json_encode(array("items" => $daily, "allitems" => $mainnews));
I understand that $daily has a LIMIT 1 with it, but others like $mainnews will be big arrays. How would I set up the PHP echo and get it back in JS? I guess if all else fails, I could do multiple ajax calls but that would be a waste...