向各位求救
$sql="select * from xym_pic";
$res=mysql_query($sql,$conn);
while ($row=mysql_fetch_assoc($res)){
$data[]=$row;
}// 随机抽取9条记录以模拟实际情况
$keys = array_rand($data, 10);
$json = array();
foreach($keys as $key){
$json[] = $data[$key];
}
echo json_encode( $json );
这段代码中瀑布流data.php部分的代码,每次获取一次,就从数据库里面取出数据 放到数组$data[]里面,原来的是随机去取9条记录,我想让这段编程,每次获取去除按时间排序的9条记录,就是第一次取出来的是0-9,第二次是10-9,以此类推!那位能帮忙告诉怎么取出数据呢?万分感谢啊!小弟奉上100分,解决了另加!!!如果好心人原意加QQ指导,那是相当的感激啊:QQ 2 7 7 6 2 8 1 8 1
回复讨论(解决方案)
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 );
感谢版主的回复 已经解决了 谢谢谢谢!!!!!!!!!
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 );
我还有一个小问题,就是我数据库里面一共有 80多条记录,每次取出来九条,取出来8次,就取完了,但是我刷新页面的时候session还在,我就取不出来数据了,请问怎么解决一下呢?谢谢啊
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 );
我还有一个小问题,就是我数据库里面一共有 80多条记录,每次取出来九条,取出来8次,就取完了,但是我刷新页面的时候session还在,我就取不出来数据了,请问怎么解决一下呢?谢谢啊
瀑布流应该也不会用session存放吧?应该是和分页一样通过请求参数确定数据起始吧
取不到了就从头再取
取不到了就从头再取
现在就是因为取不到了,我判断如果结果集是空的话就销毁session,刷新页面还是取不出来数据
取不到了就从头再取
现在就是因为取不到了,我判断如果结果集是空的话就销毁session,刷新页面还是取不出来数据
结果集为空的话 我让session销毁了,但是他又会无限循环了
我想结果集为空了,就不取结果了,直到页面刷新,才重新计数
请问怎么解决呢
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);if(mysql_num_rows($res) ==0) { $last = $_SESSION['last'] = 0; $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 )
取不到了就从头再取
现在就是因为取不到了,我判断如果结果集是空的话就销毁session,刷新页面还是取不出来数据
结果集为空的话 我让session销毁了,但是他又会无限循环了
我想结果集为空了,就不取结果了,直到页面刷新,才重新计数
请问怎么解决呢
这个 代码最后的结果集 json是返回给一个JS文件的,js判断页面位置不停的加载新内容,我即使销毁了session,一加载也会重新开始获取数据!
这个很是头疼啊!
你究竟想要做什么?
你究竟想要做什么?
就是这个瀑布流,我想按条取出来最新的80条数据,然后就终止了,我刷新页面,再重新取数据!
现在这个瀑布流的机制是,静态页面调用js,js控制页面当前位置,距离底部多少个px之后获取php文件,这段php代码没问题,就是js获取的时候,是不是得判断一下如果json为空就不在获取呢?
现在是js只要滚动就会不断的获取内容,如果php里面结果集为空,他在获取一次也就会有数据了!
取完了就注销掉 session 或设置 $_SESSION 为空
js 那边当然也需要是否有数据返回,没有的话就不再发请求
取完了就注销掉 session 或设置 $_SESSION 为空
js 那边当然也需要是否有数据返回,没有的话就不再发请求
十分感谢啊,我把JS搞一下试试!
感谢您的耐心帮助哦!!!!!!!

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools