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?