本文为大家分享了php微信公众号开发之翻页查询的具体代码,供大家参考,具体内容如下
注意:公众号列表最多只能列出8列,超出会报错
分页原理limit 开始位置 , 条数(当前页数 – 1) x 每页条数 , 每页条数limit ($page – 1) * $pagesize , $pagesize0 为开始位置mysql_num_rows 条数require() 与 require_once() 开始加载,错误停止include() 与 include_once() 使用加蚊子为什么不会被雨滴砸死载,错误跳过ceil 进一 向上取整原理:
总共10条,每页9条n条sum 总共几页 ceil ( n / 9 )开始条数 : (当前页数 – 1 ) x 每页条数(key – 1)* 9注释:+1 是为了说明有多少页
>10 10
核心代码如下:
$postobj = simplexml_load_string($poststr, 'simplexmlelement', libxml_nocdata); $fromurname = $postobj->fromurname; $tourname = $postobj->tourname; $type = $postobj->msgtype; $customevent = $postobj->event; $latitude = $postobj->location_x; $longitude = $postobj->location_y; $keyword = trim($postobj->content); $time = time(); $texttpl = "<xml> <tourname><![cdata[%s]]></tourname> <fromurname><![cdata[%s]]></fromurname> <createtime>%s</createtime> <msgtype><![cdata[%s]]></msgtype> <content>%s</content> <funcflag>0</funcflag> </xml>"; switch ($type) { ca "event"; if ($customevent=="subscribe") {$contentstr = "感谢你的关注\n栏目正在搭建,敬请期待\n回复1看视频教程";} break; ca "image"; $contentstr = "你的图片很棒!"; break; ca "location"; $contentstr = "你的纬度是{$latitude},经度是{$longitude},我已经锁定!"; break; ca "link" ; $contentstr = "你的链接有病毒吧!"; break; ca "text"; include("coon.php"); $num = "lect * from `kecheng` "; $que=mysql_query($num); $no=mysql_num_rows($que);//获得条数 $sumpage=ceil($no/7); $page=(intval($keyword)-1)*7; $total=$no-$page+1; if($total>8) {$total=8;} $sql = "lect * from `kecheng` order by `id` desc limit {$page},7"; $query=mysql_query($sql); $newstpl = "<xml> <tourname><![cdata[%s]]></tourname> <fromurname><![cdata[%s]]></fromurname> <createtime>%s</createtime> <msgtype><![cdata[news]]></msgtype> <articlecount>$total</articlecount> <articles> <item> <title><![cdata[总共{$sumpage}页,输入页数翻页]]></title> <description><![cdata[]]></description> <picurl>http://autoguitar.duapp.com/1.jpg</picurl> <url><![cdata[]]></url> </item>"; while($rs=mysql_fetch_array($query)){ $newstpl.="<item> <title>$湖北电视教育频道rs[content]</title> <description><![cdata[]]></description> <picurl>http://dq095.applinzi.com/2.jpg</picurl> <url><![cdata[]]></url> </item>"; } $newstpl.="</articles> <funcflag>0</funcflag> </xml>"; $myresultstr = sprintf($newstpl, $fromurname, $tourname, $time); echo $myresultstr; break; default; $contentstr ="此项功能尚未开发"; } $msgtype="text"; $resultstr = sprintf($texttpl, $fromurname, $tourname, $time, $msgtype, $contentstr); echo $resultstr;
coon.php连接数据库代码如下:
<?php //用 户 名 : $ur //密 码 : $pwd //主库域名 : $host //从库域名 : sae_mysql_host_s //端 口 : $port //数据库名 : $dbname $dbname = "app_dq095"; $host = "w.rdc.sae.sina.com.cn"; $port = "3306"; $ur = "4k514n103z"; $pwd = "2402314li2j1i5im1xy2xizj5y332w2x41k2z203"; /*接着调用mysql_connect()连接服务器*/ // 连主库 $db = mysql_connect($host,$ur,$pwd); if(!$db){ die("connect rver failed: " . mysql_error($db)); } /*连接成功后立即调用mysql_lect_db()选中需要连接的数据库*/ if (!mysql_lect_db($dbname)) { die("lect databa failed: " . mysql_error($db)); } mysql_query("t names utf-8",$db); /*至此连接已完全建立,就可对当前数据库进行相应的操作了*/ /*!!!注意,无法再通过本次连接调用mysql_lect_db来切换到其它数据库了!!!*/ /* 需要再连接其它数据库,请再使用mysql_connect+mysql_lect_db启动另一个连接*/ /** * 接下来就可以使用其它标准php mysql函数操作进行数据库操作 */
index.php整体代码如下:
<?php/** * wechat php test *///define your tokendefine("token", "weixin");$wechatobj = new wechatcallbackapitest();$wechatobj->responmsg();class wechatcallbackapitest{ public function valid() { $echostr = $_get["echostr"]; //valid signature , option if($this->checksignature()){ echo $echostr; exit; } } public function responmsg() { //get post data, may be due to the different environments $poststr = $globals["http_raw_post_data"]; //extract post data if (!empty($poststr)){ $postobj = simplexml_load_string($poststr, 'simplexmlelement', libxml_nocdata); $fromurname = $postobj->fromurname; $tourname = $postobj->tourname; $type = $postobj->msgtype; $customevent = $postobj->event; $latitude = $postobj->location_x; $longitude = $postobj->location_y; $keyword = trim($postobj->content); $tim空间主人寄语文字e = time(); $texttpl = "<xml> <tourname><![cdata[%s]]></tourname> <fromurname><![cdata[%s]]></fromurname> <createtime>%s</createtime> <msgtype><![cdata[%s]]></msgtype> <content>%s</content> <funcflag>0</funcflag> </xml>"; switch ($type) { ca "event"; if ($customevent=="subscribe") {$contentstr = "感谢你的关注\n栏目正在搭建,敬请期待\n回复1看视频教程";} break; ca "image"; $contentstr = "你的图片很棒!"; break; ca "location"; $contentstr = "你的纬度是{$latitude},经度是{我是消防员$longitude},我已经锁定!"; break; ca "link" ; $contentstr = "你的链接有病毒吧!"; break; ca "text"; include("coon.php"); $num = "lect * from `kecheng` "; $que=mysql_query($num); $no=mysql_num_rows($que);//获得条数 $sumpage=ceil($no/7); $page=(intval($keyword)-1)*7; $total=$no-$page+1; if($total>8) {$total=8;} $sql = "lect * from `kecheng` order by `id` desc limit {$page},7"; $query=mysql_query($sql); $newstpl = "<xml> <tourname><![cdata[%s]]></tourname> <fromurname><![cdata[%s]]></fromurname> <createtime>%s</createtime> <msgtype><![cdata[news]]></msgtype> <articlecount>$total</articlecount> <articles> <item> <title><![cdata[总共{$sumpage}页,输入页数翻页]]></title> <description><![cdata[]]></description> <picurl>http://autoguitar.duapp.com/1.jpg</picurl> <url><![cdata[]]></url> </item>"; while($rs=mysql_fetch_array($query)){ $newstpl.="<item> <title>$rs[content]</title> <description><![cdata[]]></description> <picurl>http://dq095.applinzi.com/2.jpg</picurl> <url><![cdata[]]></url显微镜成像> </item>"; } $newstpl.="</articles> <funcflag>0</funcflag> </xml>"; $myresultstr = sprintf($newstpl, $fromurname, $tourname, $time); echo $myresultstr; break; default; $contentstr ="此项功能尚未开发"; } $msgtype="text"; $resultstr = sprintf($texttpl, $fromurname, $tourname, $time, $msgtype, $contentstr); echo $resultstr; } } private function checksignature() { $signature = $_get["signature"]; $timestamp = $_get["timestamp"]; $nonce = $_get["nonce"]; $token = token; $tmparr = array($token, $timestamp, $nonce); sort($tmparr); $tmpstr = implode( $tmparr ); $tmpstr = sha1( $tmpstr ); if( $tmpstr == $signature ){ return true; }el{ return fal; } }}?>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持www.887551.com。
本文发布于:2023-04-06 16:58:43,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/03c26902170720bbf03e0a03e6fcf873.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:php微信公众号开发之翻页查询.doc
本文 PDF 下载地址:php微信公众号开发之翻页查询.pdf
留言与评论(共有 0 条评论) |