: Questions about getting data in this code!

Source: Internet
Author: User
For help: Question about getting data in this code !! This post was edited by XiaoShengbboy from 2013-06-1400: 42: 16 to ask for help $ sqlselect & nbsp; * & nbsp; from & nbsp; xym_pic; $ resmysql_query ($ SQL, $ conn); while & nbsp; ($ rowmysql_fet for help: the problem about getting data in this code !!

This post was last edited by XiaoShengbboy at 00:42:16

For help
$ SQL = "select * from xym_pic ";
$ Res = mysql_query ($ SQL, $ conn );
While ($ row = mysql_fetch_assoc ($ res )){
$ Data [] = $ row;
} // Nine records are randomly selected to simulate the actual situation.
$ Keys = array_rand ($ data, 10 );
$ Json = array ();
Foreach ($ keys as $ key ){
$ Json [] = $ data [$ key];
}
Echo json_encode ($ json );
Waterfall data in this code. the php code retrieves data from the database every time it is obtained and put it in the array $ data []. The original code is to randomly retrieve nine records. I want to program this section, 9 records sorted by time are Retrieved each time, that is, 0-9 is obtained for the first time, 10-9 is obtained for the second time, and so on! Can someone tell me how to retrieve the data? Thank you! The younger brother scored 100 points and added the solution !!! If a good person wishes to add QQ guidance, it would be quite grateful: QQ 2 7 7 6 2 8 1 8 1

Share:


------ Solution --------------------
session_start();
if(! isset($_SESSION['last'])) $_SESSION['last'] = 0;
$last = $_SESSION['last'];

$sql="select * from xym_pic limit $last,9";
$res=mysql_query($sql,$conn);
while ($row=mysql_fetch_assoc($res)){
$data[]=$row;
}
$_SESSION['last'] += count($data);
echo json_encode( $data )
;
------ Solution --------------------
Reference:
Quote: reference:

session_start();
if(! isset($_SESSION['last'])) $_SESSION['last'] = 0;
$last = $_SESSION['last'];

$sql="select * from xym_pic limit $last,9";
$res=mysql_query($sql,$conn);
while ($row=mysql_fetch_assoc($res)){
$data[]=$row;
}
$_SESSION['last'] += count($data);
echo json_encode( $data )
;


I still have a small problem, that is, there are more than 80 records in my database. each time nine records are retrieved and eight records are retrieved, they are all retrieved, but when I refresh the page, the session is still there and I cannot retrieve the data. how can I solve this problem? Thank you.

Should waterfall streams not be stored in sessions? It should be the same as paging. use the request parameter to determine the data starting point.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.