Home  >  Article  >  Backend Development  >  请教PHP生成JSON分页有关问题

请教PHP生成JSON分页有关问题

WBOY
WBOYOriginal
2016-06-13 12:46:09954browse

请问PHP生成JSON分页问题
最近在搞生成PHP 生成JSON,想实现分页,下边代码已能把数组生成了,分页要怎实现了?想实现每10条分一次页
    
  //connection information
  $host = "XXX";
  $user = "XXX";
  $password = "XX";
  $database = "XX";
    
    //make connection
  $server = mysql_connect($host, $user, $password);
  $connection = mysql_select_db($database, $server);
    
    //query the database
mysql_query('set character set "utf8"');
  $query = mysql_query("SELECT * FROM akb order by infoid desc");
 
    //start json object
    $json = '{"tags":['; 
    
    //loop through and return results
  for ($x = 0; $x      $row = mysql_fetch_assoc($query);
    $infoid=$row["InfoId"];
  $Title=$row["Title"]; 
   $pic=$row["LogoImg"]; 
   $bpic=$row["LogoImg2"];
   $time=$row["AccTime"];
   $info=$row["Burden"];
    $url=$row["ExtUrl"];
   
   
   $json .= '{"id":"'. $infoid .'","title":"'.$Title.'","pic":"'.$pic.'","bpic":"'.$bpic.'","time":"'.$time.'","info":"'. $info .'","url":"'. $url.'"}';
        
      
if ($x              $json .= ",";
       else
           $json .= "]}";
  }
    
    $response = $_GET["callback"] . $json;
    echo $response;

    //close connection
    mysql_close($server);

?>

php json
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn