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.