Php uses foreach to output messages and add the paging function to them. how can this problem be achieved?

Source: Internet
Author: User
Php uses foreach to output messages and add the paging function to them. how can this problem be achieved? Here is my input. php code:
Include ('Common/function. php ');
Function show_message () {$ SQL = "SELECT * FROM message order by time DESC ";
$ Result = mysql_query ($ SQL );
$ Num = mysql_num_rows ($ result );
For ($ I = 0; $ I
{$ Row = mysql_fetch_assoc ($ result); $ arr [$ I] = $ row;} return $ arr ;}
$ I = 0;
?>



Comment page





Homepage
















";?>
Message time: ";?>















In this code, you can enter a message, generate a message on the same page, and use foreach to output both the message box and the message time. Now I want to display the generated messages on pages, but I have been searching for it online for a long time. I know what the paging function is like, but I just don't know how to embed it into the code above. It's been a long time. it's really urgent ~~ Could you help me? I just learned php. I hope I can embed the paging code into the above code.
Thank you very much ~~


Reply to discussion (solution)

$ SQL = "SELECT * FROM message order by time DESC limit x, x ";
Research limit attributes

Http://topic.csdn.net/u/20120117/11/c2618d08-b88c-4586-8b00-f1938f5c7792.html

Http://bbs.csdn.net/topics/380148088

Find a paging class online
You need to do this when calling:
1. query the total number of records that match the results and save the number to a variable. in this case, two values are required to be input to instantiate a paging object, one is the total number of records, and the other is the number of records you want to display on each page, such as: $ fpage = new FPage ($ total, $ page_num)
2. there should be a limit method or similar method in the $ fpage object. put this method into the statement you need to limit the number of queries, for example, select * from table1 $ fpage-> limit ()
Then OK.

Can I embed paging code into my code above? I just learned php. I checked a lot of paging code, but I just don't know where to put it?

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.