0

我想知道是否可以将许多查询组合到一个数组中并返回它。问题是其中一些查询已经是数组......这就是我的意思:

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
      });
    });

这是带有查询的 php 文件:

<?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;
    }
?>

如果我有更多这样的查询,我如何将它们收集在一起以便能够执行以下操作:

echo json_encode(array("items" => $daily, "allitems" => $mainnews));

我知道 $daily 有一个 LIMIT 1 ,但其他像 $mainnews 将是大数组。我将如何设置 PHP 回显并在 JS 中取回它?我想如果一切都失败了,我可以做多个 ajax 调用,但那将是一种浪费......

4

0 回答 0