Home > Backend Development > PHP Tutorial > Similar to Google search paging under phpZF framework_PHP tutorial

Similar to Google search paging under phpZF framework_PHP tutorial

WBOY
Release: 2016-07-13 10:38:47
Original
1120 people have browsed it
<p></p> <h3> <i>[Code]</i> [PHP]Code</h3> view source <embed allowscriptaccess="always" flashvars="highlighterId=highlighter_619417" height="16" id="highlighter_619417_clipboard" menu="false" src="http://www.oschina.net/js/syntax-highlighter-2.1.382/scripts/clipboard.swf" title="copy to clipboard" type="application/x-shockwave-flash" width="16" wmode="transparent"></embed> print? <tbody> <code>01</code> <code class="comments">/**</code> </tbody> <tbody> <code>02</code> <code class="spaces">     </code><code class="comments">*</code> </tbody> <tbody> <code>03</code> <code class="spaces">     </code><code class="comments">* @param unknown_type $model 表类型</code> </tbody> <tbody> <code>04</code> <code class="spaces">     </code><code class="comments">* @param unknown_type $ncontroller 那个控制器提交的controller</code> </tbody> <tbody> <code>05</code> <code class="spaces">     </code><code class="comments">* @param unknown_type $naction 那个action提交的action</code> </tbody> <tbody> <code>06</code> <code class="spaces">     </code><code class="comments">*/</code> </tbody> <tbody> <code>07</code> <code class="spaces">    </code><code class="keyword">public</code> <code class="keyword">function</code> <code class="plain">fenyepage2(</code><code class="variable">$model</code><code class="plain">,</code><code class="variable">$ncontroller</code><code class="plain">,</code><code class="variable">$naction</code><code class="plain">){</code> </tbody> <tbody> <code>08</code> <code class="spaces">        </code><code class="keyword">if</code><code class="plain">(!isset(</code><code class="variable">$_SESSION</code><code class="plain">))</code> </tbody> <tbody> <code>09</code> <code class="spaces">        </code><code class="plain">{session_start();}</code> </tbody> <tbody> <code>10<code>10</code> <code class="spaces">        <code class="spaces">        </code><code class="variable">$pageSize<code class="variable">$pageSize</code> <code class="plain">= </code>= <code class="variable">$_SESSION</code><code class="variable">$_SESSION<code class="plain">[</code><code class="string">'pagesize'</code>[<code class="plain">];</code><code class="string">'pagesize'</code></code></code></code></code> </tbody> <tbody>];<code>11</code> <code class="spaces">        </code> <code class="variable">$pageNow</code> <code>11<code class="plain">= </code> <code class="spaces">        <code class="variable">$_SESSION</code><code class="variable">$pageNow<code class="plain">[</code> <code class="string">'pagenow'</code>= <code class="plain">];</code><code class="variable">$_SESSION</code></code></code></code> </tbody> <tbody>[<code>12</code><code class="string">'pagenow'<code class="spaces">        </code><code class="variable">$offset</code>];<code class="plain">= (</code> <code class="variable">$pageNow</code> <code class="plain">-1)*</code> <code>12<code class="variable">$pageSize</code> <code class="spaces">        <code class="plain">;</code><code class="variable">$offset</code></code></code></code> </tbody> <tbody>= (<code>13</code><code class="variable">$pageNow<code class="spaces">        </code><code class="variable">$db</code>-1)*<code class="plain">= </code><code class="variable">$pageSize<code class="variable">$this</code><code class="plain">->getAdapter();</code>;</code></code> </tbody> <tbody> <code>14</code> <code>13<code class="spaces">        </code> <code class="spaces">        <code class="variable">$select</code><code class="variable">$db<code class="plain">= </code> <code class="variable">$db</code>= <code class="plain">->select();</code><code class="variable">$this</code></code></code></code> </tbody> <tbody>->getAdapter();<code>15</code> <code class="spaces">        </code> <code class="variable">$select</code> <code>14<code class="plain">->from(</code> <code class="spaces">        <code class="string">'student'</code><code class="variable">$select<code class="plain">,</code> <code class="string">'*'</code>= <code class="plain">);</code><code class="variable">$db</code></code></code></code> </tbody> <tbody>->select();<code>16</code> <code class="spaces">        </code> <code class="keyword">if</code> <code>15<code class="plain">(!isset(</code> <code class="spaces">        <code class="variable">$_SESSION</code><code class="variable">$select<code class="plain">))</code></code></code></code> </tbody>->from(<tbody><code class="string">'student'<code>17</code><code class="spaces">        </code>,<code class="plain">{session_start();}</code><code class="string">'*'</code></code></tbody> <tbody>);<code>18</code> <code class="spaces">        </code> <code class="keyword">if</code> <code>16<code class="plain">(</code> <code class="spaces">        <code class="variable">$_SESSION</code><code class="keyword">if<code class="plain">[</code><code class="string">'qsname'</code>(!isset(<code class="plain">]!=</code><code class="variable">$_SESSION<code class="string">""</code><code class="plain">){</code>))</code></code></code></code> </tbody> <tbody> <code>19</code> <code>17<code class="spaces">            </code> <code class="spaces">        <code class="variable">$sname</code><code class="plain">= </code>{session_start();}<code class="variable">$_SESSION</code> <code class="plain">[</code> <code class="string">'qsname'</code> <code>18<code class="plain">];</code> <code class="spaces">        </code></code></code></code> </tbody> <code class="keyword">if<tbody> <code>20</code>(<code class="spaces">            </code><code class="variable">$_SESSION<code class="variable">$select</code><code class="plain">->where(</code>[<code class="string">'sname like ?'</code><code class="string">'qsname'<code class="plain">,</code><code class="string">"%$sname%"</code>]!=<code class="plain">);</code><code class="string">""</code></code></code> </tbody> <tbody>){<code>21</code> <code class="spaces">        </code> <code class="plain"> <code>19 <code class="spaces">            <code class="variable">$sname = <code class="variable">$_SESSION[<code class="string">'qsname']; <code>20 <code class="spaces">            <code class="variable">$select->where(<code class="string">'sname like ?',<code class="string">"%$sname%"); <code>21 <code class="spaces">        }</code> </code></code></code></code></code></code></code></code></code></code></code></code> </tbody> <tbody> <code>22<code>22</code> <code class="spaces">        <code class="spaces">        </code><code class="keyword">if<code class="keyword">if</code><code class="plain">(<code class="plain">(</code><code class="variable">$_SESSION<code class="variable">$_SESSION</code><code class="plain">[<code class="plain">[</code><code class="string">'qsaddress'<code class="string">'qsaddress'</code><code class="plain">]!=<code class="plain">]!=</code><code class="string">""<code class="string">""</code><code class="plain">){<code class="plain">){</code> </code></code></code></code></code></code></code></code></code></code> </tbody> <tbody> <code>23<code>23</code> <code class="spaces">            <code class="spaces">            </code><code class="variable">$saddress<code class="variable">$saddress</code> <code class="plain">= <code class="plain">= </code><code class="variable">$_SESSION<code class="variable">$_SESSION</code><code class="plain">[<code class="plain">[</code><code class="string">'qsaddress'<code class="string">'qsaddress'</code><code class="plain">];<code class="plain">];</code> </code></code></code></code></code></code></code></code> </tbody> <tbody> <code>24<code>24</code> <code class="spaces">            <code class="spaces">            </code><code class="variable">$select<code class="variable">$select</code><code class="plain">->where(<code class="plain">->where(</code><code class="string">'saddress like ?'<code class="string">'saddress like ?'</code><code class="plain">,<code class="plain">,</code><code class="string">"%$saddress%"<code class="string">"%$saddress%"</code><code class="plain">);<code class="plain">);</code> </code></code></code></code></code></code></code></code> </tbody> <tbody> <code>25<code>25</code> <code class="spaces">        <code class="spaces">        </code><code class="plain">}<code class="plain">}</code> </code></code></code> </tbody> <tbody> <code>26<code>26</code> <code class="spaces">        <code class="spaces">        </code><code class="keyword">if<code class="keyword">if</code><code class="plain">(<code class="plain">(</code><code class="variable">$_SESSION<code class="variable">$_SESSION</code><code class="plain">[<code class="plain">[</code><code class="string">'qsdept'<code class="string">'qsdept'</code><code class="plain">]!=<code class="plain">]!=</code><code class="string">""<code class="string">""</code><code class="plain">){<code class="plain">){</code> </code></code></code></code></code></code></code></code></code></code> </tbody> <tbody> <code>27<code>27</code> <code class="spaces">            <code class="spaces">            </code><code class="variable">$sdept<code class="variable">$sdept</code> <code class="plain">= <code class="plain">= </code><code class="variable">$_SESSION<code class="variable">$_SESSION</code><code class="plain">[<code class="plain">[</code><code class="string">'qsdept'<code class="string">'qsdept'</code><code class="plain">];<code class="plain">];</code> </code></code></code></code></code></code></code></code> </tbody> <tbody> <code>28<code>28</code> <code class="spaces">            <code class="spaces">            </code><code class="variable">$select<code class="variable">$select</code><code class="plain">->where(<code class="plain">->where(</code><code class="string">'sdept like ?'<code class="string">'sdept like ?'</code><code class="plain">,<code class="plain">,</code><code class="string">"%$sdept%"<code class="string">"%$sdept%"</code><code class="plain">);<code class="plain">);</code> </code></code></code></code></code></code></code></code> </tbody> <tbody> <code>29<code>29</code> <code class="spaces">        <code class="spaces">        </code><code class="plain">}<code class="plain">}</code> </code></code></code> </tbody> <tbody> <code>30<code>30</code> <code class="spaces">        <code class="spaces">        </code><code class="variable">$coutNews<code class="variable">$coutNews</code> <code class="plain">= <code class="plain">= </code><code class="variable">$db<code class="variable">$db</code><code class="plain">->fetchAll(<code class="plain">->fetchAll(</code><code class="variable">$select<code class="variable">$select</code><code class="plain">);<code class="plain">);</code> </code></code></code></code></code></code></code></code> </tbody> <tbody> <code>31<code>31</code> <code class="spaces">        <code class="spaces">        </code><code class="variable">$pageCount<code class="variable">$pageCount</code> <code class="plain">= <code class="plain">= </code><code class="functions">ceil<code class="functions">ceil</code><code class="plain">(<code class="plain">(</code><code class="functions">count<code class="functions">count</code><code class="plain">(<code class="plain">(</code><code class="variable">$coutNews<code class="variable">$coutNews</code><code class="plain">)/<code class="plain">)/</code><code class="variable">$pageSize<code class="variable">$pageSize</code><code class="plain">);<code class="plain">);</code> </code></code></code></code></code></code></code></code></code></code></code></code> </tbody> <tbody> <code>32<code>32</code> <code class="spaces">        <code class="spaces">        </code><code class="variable">$select<code class="variable">$select</code><code class="plain">->limit(<code class="plain">->limit(</code><code class="variable">$pageSize<code class="variable">$pageSize</code><code class="plain">,<code class="plain">,</code><code class="variable">$offset<code class="variable">$offset</code><code class="plain">);<code class="plain">);</code><code class="comments">//第一个参数:总共显示多少个。第二个参数:从第几个开始显示</code> </code></code></code></code></code></code></code></code> </tbody> <tbody> <code>33<code>33</code> <code class="spaces">        <code class="spaces">        </code><code class="variable">$res<code class="variable">$res</code> <code class="plain">= </code>= <code class="variable">$db</code><code class="variable">$db<code class="plain">->fetchAll(</code><code class="variable">$select</code>->fetchAll(<code class="plain">);</code><code class="variable">$select</code></code></code></code></code> </tbody> <tbody>);<code>34</code> <code class="spaces">        </code> <code class="variable">$native</code> <code>34<code class="plain">= null;</code> <code class="spaces">        </code></code> </tbody> <code class="variable">$native<tbody> <code>35</code>= null;<code class="spaces">        </code> <code class="variable">$native</code> <code class="plain">= </code> <code>35<code class="string">"<a href=&#39;$ncontroller$naction?pageNow=1&pagesize=$pageSize&#39;>首页</a>&nbsp"</code> <code class="spaces">        <code class="plain">;</code><code class="variable">$native</code></code></code> </tbody> <tbody>= <code>36</code><code class="string">"<a href='\$ncontroller\$naction?pageNow=1&pagesize=$pageSize'>首页</a>&nbsp"<code class="spaces">        </code><code class="keyword">if</code>;<code class="plain">(</code> <code class="variable">$pageNow</code> <code class="plain">>1){</code> <code>36</code></code> </tbody> <code class="spaces">        <tbody><code class="keyword">if<code>37</code><code class="spaces">            </code>(<code class="variable">$nextPage</code><code class="variable">$pageNow<code class="plain">= </code><code class="variable">$pageNow</code>>1){<code class="plain">-1;</code> </code></code></tbody> <tbody> <code>37<code>38</code> <code class="spaces">            <code class="spaces">            </code><code class="variable">$nextPage<code class="variable">$native</code> <code class="plain">.=</code>= <code class="string">" <a href=&#39;$ncontroller$naction?pageNow=$nextPage&pagesize=$pageSize&#39;>上一页</a> "</code><code class="variable">$pageNow<code class="plain">;</code></code></code></code></code> </tbody>-1;<tbody> <code>39</code> <code class="spaces">        </code> <code>38<code class="plain">}</code> <code class="spaces">            </code></code> </tbody> <code class="variable">$native<tbody> <code>40</code>.=<code class="spaces">            </code><code class="string">" <a href='\$ncontroller\$naction?pageNow=$nextPage&pagesize=$pageSize'>上一页</a> "<code class="keyword">if</code><code class="plain">((</code>;<code class="variable">$pageNow</code> <code class="plain">-1)>5){</code> </code> </tbody> <code>39<tbody> <code class="spaces">        <code>41</code><code class="spaces">                </code>}<code class="keyword">if</code> <code class="plain">(</code> <code class="variable">$pageNow</code> <code>40<code class="plain">+4></code> <code class="spaces">            <code class="variable">$pageCount</code><code class="keyword">if<code class="plain">){</code><code class="comments">//如果最后的页数和理应前面开始的页数小于10则</code>((</code></code></code></code> </tbody> <code class="variable">$pageNow<tbody> <code>42</code>-1)>5){<code class="spaces">                    </code> <code class="variable">$start</code> <code class="plain">= </code> <code>41<code class="variable">$pageCount</code> <code class="spaces">                <code class="plain">-9;</code><code class="keyword">if<code class="comments">//开始的页数和结束的页数相差9</code></code></code></code> </tbody>(<tbody><code class="variable">$pageNow<code>43</code><code class="spaces">                </code>+4><code class="plain">}</code><code class="variable">$pageCount<code class="keyword">else</code><code class="plain">{</code>){</code></code></tbody> <code class="comments">//如果最后的页数和理应前面开始的页数小于10则<tbody> <code>44</code> <code class="spaces">                    </code> <code>42<code class="variable">$start</code> <code class="spaces">                    <code class="plain">=</code><code class="variable">$start<code class="variable">$pageNow</code> <code class="plain">-5;</code>= <code class="comments">//开始位置和结束位置相差5</code><code class="variable">$pageCount</code></code></code></code> </tbody> <tbody>-9;<code>45</code><code class="comments">//开始的页数和结束的页数相差9<code class="spaces">                </code> <code class="plain">}</code> </code> </tbody> <code>43<tbody> <code class="spaces">                <code>46</code><code class="spaces">            </code>}<code class="plain"><code class="keyword">else{ <code>44 <code class="spaces">                    <code class="variable">$start=<code class="variable">$pageNow-5;<code class="comments">//开始位置和结束位置相差5 <code>45 <code class="spaces">                } <code>46 <code class="spaces">            }</code><code class="keyword">else<code class="keyword">else</code><code class="plain">{</code>{</code></code></code></code></code></code></code></code></code></code></code></code> </tbody> <tbody> <code>47</code> <code>47<code class="spaces">                </code> <code class="spaces">                <code class="variable">$start</code><code class="variable">$start<code class="plain">= </code> <code class="functions">floor</code>= <code class="plain">((</code><code class="functions">floor<code class="variable">$pageNow</code><code class="plain">-1)/10)*10+1;</code>((</code></code></code></code> </tbody> <code class="variable">$pageNow<tbody> <code>48</code>-1)/10)*10+1;<code class="spaces">            </code> <code class="plain">}</code> </tbody> <code>48<tbody> <code class="spaces">            <code>49</code><code class="spaces">            </code>}<code class="keyword">if</code> <code class="plain">(</code> <code class="variable">$pageCount</code> <code>49<code class="plain">>=</code> <code class="spaces">            <code class="variable">$start</code><code class="keyword">if<code class="plain">+10){</code></code></code></code></code> </tbody>(<tbody><code class="variable">$pageCount<code>50</code><code class="spaces">                </code>>=<code class="variable">$index</code><code class="variable">$start<code class="plain">= </code><code class="variable">$start</code>+10){<code class="plain">+10;</code> </code></code></tbody> <tbody> <code>50<code>51</code> <code class="spaces">                <code class="spaces">            </code><code class="variable">$index<code class="plain">}</code> </code></code></code> </tbody>= <tbody><code class="variable">$start<code>52</code><code class="spaces">            </code>+10;<code class="keyword">else</code> <code class="plain">{</code> </code></tbody> <code>51<tbody> <code class="spaces">            <code>53</code><code class="spaces">                </code>}<code class="variable">$index</code> <code class="plain">= </code> <code class="variable">$pageCount</code> <code>52<code class="plain">+1;</code> <code class="spaces">            </code></code></code> </tbody> <code class="keyword">else<tbody> <code>54</code>{<code class="spaces">            </code> <code class="plain">}</code> </tbody> <code>53<tbody> <code class="spaces">                <code>55</code><code class="variable">$index</code></code> </tbody> <tbody>= <code>56</code><code class="variable">$pageCount<code class="spaces">            </code><code class="keyword">for</code>+1;<code class="plain">(;</code> <code class="variable">$start</code> <code class="plain"><</code> <code>54<code class="variable">$index</code> <code class="spaces">            <code class="plain">;</code><code class="variable">$start</code>}<code class="plain">++){</code> </tbody> <tbody> <code>55<code>57</code>   <code class="spaces"> </code> <code class="variable">$native</code> <code>56<code class="plain">.=</code> <code class="spaces">            <code class="string">" <a href='$ncontroller$naction?pageNow=$start&pagesize=$pageSize'>$start</a>"</code><code class="keyword">for<code class="plain">;</code></code></code> </tbody>(;<tbody><code class="variable">$start<code>58</code><code class="spaces">            </code><<code class="plain"><code class="variable">$index<🎜><🎜>;<🎜><code class="variable">$start<🎜><🎜>++){<🎜> <🎜> <🎜> <code>57<🎜> <code class="spaces">                <🎜><code class="variable">$native<🎜><🎜>.=<🎜><code class="string">" <a href='\$ncontroller\$naction?pageNow=$start&pagesize=$pageSize'>$start</a>"; <code>58 <code class="spaces">            }</code> </code></code></tbody> <tbody> <code>59<code>59</code> <code class="spaces">        <code class="spaces">        </code><code class="keyword">if<code class="keyword">if</code><code class="plain">(<code class="plain">(</code><code class="variable">$pageNow<code class="variable">$pageNow</code><code class="plain"><<code class="plain"><</code><code class="variable">$pageCount<code class="variable">$pageCount</code><code class="plain">){<code class="plain">){</code> </code></code></code></code></code></code></code></code> </tbody> <tbody> <code>60<code>60</code> <code class="spaces">            <code class="spaces">            </code><code class="variable">$nextPage<code class="variable">$nextPage</code> <code class="plain">= <code class="plain">= </code><code class="variable">$pageNow<code class="variable">$pageNow</code><code class="plain">+1;<code class="plain">+1;</code> </code></code></code></code></code></code> </tbody> <tbody> <code>61<code>61</code> <code class="spaces">            <code class="spaces">            </code><code class="variable">$native<code class="variable">$native</code><code class="plain">.=<code class="plain">.=</code><code class="string">"  <a href='\$ncontroller\$naction?pageNow=$nextPage&pagesize=$pageSize'>下一页</a> "<code class="string">" <a href='$ncontroller$naction?pageNow=$nextPage&pagesize=$pageSize'>下一页</a> "</code><code class="plain">;  <code class="plain">;  </code> </code></code></code></code></code></code> </tbody> <tbody> <code>62<code>62</code> <code class="spaces">        <code class="spaces">        </code><code class="plain">}<code class="plain">}</code> </code></code></code> </tbody> <tbody> <code>63<code>63</code>   </code> </tbody> <tbody> <code>64<code>64</code> <code class="spaces">        <code class="spaces">        </code><code class="variable">$native<code class="variable">$native</code><code class="plain">.=<code class="plain">.=</code><code class="string">"  <a href='\$ncontroller\$naction?pageNow=$pageCount&pagesize=$pageSize'>末页</a> "<code class="string">" <a href='$ncontroller$naction?pageNow=$pageCount&pagesize=$pageSize'>末页</a> "</code><code class="plain">;<code class="plain">;</code> </code></code></code></code></code></code> </tbody> <tbody> <code>65<code>65</code> <code class="spaces">        <code class="spaces">        </code><code class="variable">$native<code class="variable">$native</code><code class="plain">.=<code class="plain">.=</code><code class="string">"  当前{$pageNow}||总共{$pageCount}页"<code class="string">" 当前{$pageNow}||总共{$pageCount}页"</code><code class="plain">;<code class="plain">;</code> </code></code></code></code></code></code> </tbody> <tbody> <code>66<code>66</code> <code class="spaces">        <code class="spaces">        </code><code class="variable">$model<code class="variable">$model</code><code class="plain">->arrs = <code class="plain">->arrs = </code><code class="variable">$res<code class="variable">$res</code><code class="plain">;<code class="plain">;</code> </code></code></code></code></code></code> </tbody> <tbody> <code>67<code>67</code> <code class="spaces">        <code class="spaces">        </code><code class="variable">$model<code class="variable">$model</code><code class="plain">->native = <code class="plain">->native = </code><code class="variable">$native<code class="variable">$native</code><code class="plain">;<code class="plain">;</code> </code></code></code></code></code></code> </tbody> <tbody> <code>68<code>68</code> <code class="spaces">    <code class="spaces">    </code><code class="plain">}<code class="plain">}</code> </code></code></code> </tbody> <br> <p align="left"></p> <div style="display:none;"> <span id="url" itemprop="url">http://www.bkjia.com/PHPjc/735075.html</span><span id="indexUrl" itemprop="indexUrl">www.bkjia.com</span><span id="isOriginal" itemprop="isOriginal">true</span><span id="isBasedOnUrl" itemprop="isBasedOnUrl">http://www.bkjia.com/PHPjc/735075.html</span><span id="genre" itemprop="genre">TechArticle</span><span id="description" itemprop="description">[代码] [PHP]代码 view source print? 01 /** 02 * 03 * @param unknown_type $model 表类型 04 * @param unknown_type $ncontroller 那个控制器提交的controller 05 * @param u...</span> </div> <div class="art_confoot"></div></code></code></code></code></code></code></code></code></code></code></code></code></code>
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