2015035 Shuangseqiu Lottery Results Create backward/forward buttons for query results

WBOY
Release: 2016-07-29 08:34:33
Original
4928 people have browsed it

There have been a lot of questions on the Support Forums recently about how to create a link that looks like "backward 1 2 3 4 5 forward" for a search result. I hope the script below helps you add this functionality to your search results pages. This example was written specifically for MySQL, but can be easily adapted for other SQL engines.
Since every application is different, I use some common statements for MySQL query processing. The TABLE name should be replaced with your actual table name. YOUR CONDITIONAL HERE should be replaced with your where condition, and WHATEVER should be replaced with the field by which you wish to sort the results (don't forget to add DESC if your application requires descending order).
$limit=20; // Returned rows
$numresults=mysql_query("select * from TABLE where YOUR CONDITIONAL HERE order by WHATEVER");
$numrows=mysql_num_rows($numresults);
// Then determine whether the offset has been passed to the script, if not set to 0
if (empty($offset)) {
$offset=0;
}
// Get the result
$result=mysql_query("select id,name, phone ".
"from TABLE where YOUR CONDITIONAL HERE ".
"order by WHATEVER limit $offset,$limit");
// Now the returned results can be displayed
while ($data=mysql_fetch_array($result)) {
//Include here the code to display the results as you wish
}
// Then we need to generate links to other results
if ($offset==1) { // If offset is 0, ignore the PREV link
                                                         prevoffset=$offset-20;
 print "PREV n";
}
// Calculate the number of pages to be linked
$pages=intval ($numrows/$limit);
// If there is no remainder after division, $pages now contains the integer value of the required pages
if ($numrows%$limit) {
      // If there is a remainder then add one page
     $pages++;
}
for ($i=1;$i<=$pages;$i++) { // Loop
$newoffset=$limit*($i-1);
print "$i n";
}
// Check if it is the last page
if (!(($offset/$limit)==$pages) && $pages!=1 ) {
              // If it is not the next page, give the backward link
        $newoffset=$offset+$limit;
           print "NEXT< ;p>n";
}
?>
 These may be of some use to you. Of course, you may want to make the HTML output cleaner...
 Also, please note that the link after $PHP_SELF only contains $offset. If you need to pass parameters for the where condition of the query, you also need to add these above.​

The above introduces the establishment of backward/forward buttons for the query results of the 2015035 Shuangseqiu lottery results, including the content of the 2015035 Shuangseqiu lottery results. I hope it will be helpful to friends who are interested in PHP tutorials.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!