Location: PHPKode > scripts > Paging for MySQL > paging-for-mysql/readme.html
<html>
<head>
<title>Shiegege Iseng Paging</title>
</head>

<body bgcolor="white" topmargin="0" leftmargin="0">
    <table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td width="100%" bgcolor="#008000">
          <p align="center"><b><font face="Arial" color="#FFFFFF">Shiegege Iseng
          Paging Class<br>
          shiegege at yahoo.com<br>
          </font><a href="./"><font face="Arial" color="#FFFF00">http://shiege.com/scripts/paging/</font></a></b></td>
      </tr>
    </table>
    <pre><b>Simple Sample</b></pre>
    <table border="1" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td width="100%" bgcolor="#E9E9E9"><font color="#0000cc">&lt;?<br>
          <font color="#006600">require(</font><font color="#cc0000">&quot;paging_class.php&quot;</font><font color="#006600">);<br>
          <br>
          </font>$paging<font color="#006600">=new&nbsp;</font>paging<font color="#006600">(</font>5<font color="#006600">,</font>5<font color="#006600">);<br>
          </font>$paging<font color="#006600">-&gt;</font>db<font color="#006600">(</font><font color="#cc0000">&quot;localhost&quot;</font><font color="#006600">,</font><font color="#cc0000">&quot;username&quot;</font><font color="#006600">,</font><font color="#cc0000">&quot;password&quot;</font><font color="#006600">,</font><font color="#cc0000">&quot;dbname&quot;</font><font color="#006600">);<br>
          </font>$paging<font color="#006600">-&gt;</font>query<font color="#006600">(</font><font color="#cc0000">&quot;Select
          * FROM paging ORDER BY MY_FIELD ASC&quot;</font><font color="#006600">);<br>
          <br>
          </font>$page<font color="#006600">=</font>$paging<font color="#006600">-&gt;</font>print_info<font color="#006600">();<br>
          &nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</font><font color="#cc0000">&quot;Data&nbsp;$page</font><font color="#006600">[</font><font color="#cc0000">start</font><font color="#006600">]</font><font color="#cc0000">&nbsp;-&nbsp;$page</font><font color="#006600">[</font><font color="#cc0000">end</font><font color="#006600">]</font><font color="#cc0000">&nbsp;of&nbsp;$page</font><font color="#006600">[</font><font color="#cc0000">total</font><font color="#006600">]</font><font color="#cc0000">&nbsp;</font><font color="#006600">[</font><font color="#cc0000">Total&nbsp;$page</font><font color="#006600">[</font><font color="#cc0000">total_pages</font><font color="#006600">]</font><font color="#cc0000">&nbsp;Pages</font><font color="#006600">]</font><font color="#cc0000">&lt;hr&gt;</font><font color="#006600">\n</font><font color="#cc0000">&quot;</font><font color="#006600">;<br>
          <br>
          while&nbsp;(</font><font color="#0000cc">$result</font><font color="#006600">=</font><font color="#0000cc">$paging</font><font color="#006600">-&gt;</font><font color="#0000cc">result_assoc</font><font color="#006600">())&nbsp;{<br>
          </font><font color="#ff9900">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#006600">echo&nbsp;</font><font color="#cc0000">&quot;$result</font><font color="#006600">[</font><font color="#cc0000">MY_FIELD</font><font color="#006600">]</font><font color="#cc0000">&lt;br&gt;</font><font color="#006600">\n</font><font color="#cc0000">&quot;</font><font color="#006600">;<br>
          }<br>
          <br>
          echo&nbsp;</font><font color="#cc0000">&quot;&lt;hr&gt;&quot;</font><font color="#006600">.</font><font color="#0000cc">$paging</font><font color="#006600">-&gt;</font><font color="#0000cc">print_link</font><font color="#006600">();<br>
          </font><font color="#0000cc">?&gt;<br>
          </font><br>
          </font>
          <table border="0" bgcolor="#D8D8D8" cellspacing="0" cellpadding="10" width="100%">
            <tr>
              <td width="100%">Data 6 - 10 of 14 [Total 3 Pages]
                <hr>
                MENDIDIK ANAK DALAM KANDUNG/M.KUDUS<br>
                FIQH EMPAT MADZHAB/SHALAT 1/M.KUDUS<br>
                BELAJAR KALIGRAFI 5/U.MA 1/M.KUDUS<br>
                BELAJAR DARI MONYET / 0402<br>
                BELAJAR KALIGRAFI UNTUK SD/M.KUDUS<br>
                <hr>
                <a href="./">[prev]</a> <a href="./">[1]</a> <b>[2]</b> <a href="./">[3]</a>
                <a href="./">[next]</a></td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
    <pre><b>Download
</b>Download All [<a href="./shiegege_paging.zip">here</a>]
List All [<a href="./">here</a>]</pre>
    <pre><b>Demo
</b>- <a href="./sample1.php">sample1.php</a> (simple)
- <a href="./sample2.php">sample2.php</a> (simple search)
- <a href="./sample3.php">sample3.php</a> (search demo)
- <a href="./sample4.php">sample4.php</a> (simple table result)</pre>
    <pre><b>Step 1
</b>Include paging class</pre>
    <blockquote>
      <pre><font color="#006600">require(</font><font color="#cc0000">&quot;paging_class.php&quot;</font><font color="#006600">);</font></pre>
    </blockquote>
    <pre><b>Step 2
</b>Generate new paging
<font color="#000080">Format: $classVar=paging( line , prev/next , </font><font color="#CC0000">&quot;string prev&quot;</font><font color="#000080"> , </font><font color="#CC0000">&quot;string next&quot;</font><font color="#000080"> , </font><font color="#CC0000">&quot;%%number%%&quot;</font><font color="#000080">)
</font>Note : <b>
</b>string prev, default = &quot;[prev]&quot;
string next, default = &quot;[next]&quot;
%%number%% , default = &quot;[%%number%%]&quot;</pre>
    <blockquote>
      <pre><font color="#FFFF00"><font color="#ff9900">//create 10 lines, and 5 next/prev</font>
</font><font color="#0000cc">$paging</font><font color="#006600">=new&nbsp;</font><font color="#0000cc">paging</font><font color="#006600">(</font><font color="#0000cc">10</font><font color="#006600">,</font><font color="#0000cc">5</font><font color="#006600">);</font></pre>
      <pre><font color="#FF9900">//create 10 lines, and 5 next/prev, and will generate link |prev| {[1]} {[2]} {[3]} |next|</font><font color="#FFFF00">
</font><font color="#0000cc">$paging</font><font color="#006600">=new&nbsp;</font><font color="#0000cc">paging</font><font color="#006600">( </font><font color="#0000cc">10 </font><font color="#006600">, </font><font color="#0000cc">5 , &quot;|prev|&quot; , &quot;|next|&quot; , &quot;{[%%number%%]}&quot;</font><font color="#006600">);</font></pre>
    </blockquote>
    <pre>
<b>Step 3 [Optional]
</b>Connect to MySQL
<font color="#000080">Format: $classVar-&gt;db(&quot;host&quot;,&quot;username&quot;,&quot;password&quot;,&quot;dbname&quot;)</font>
If you already connected to MySQL, ignore this line</pre>
    <blockquote>
      <pre><font color="#0000cc">$paging</font><font color="#006600">-&gt;</font><font color="#0000cc">db</font><font color="#006600">(</font><font color="#cc0000">&quot;localhost&quot;</font><font color="#006600">,</font><font color="#cc0000">&quot;username&quot;</font><font color="#006600">,</font><font color="#cc0000">&quot;password&quot;</font><font color="#006600">,</font><font color="#cc0000">&quot;dbname&quot;</font><font color="#006600">);</font></pre>
    </blockquote>
    <pre><b>Step 4</b>
MySQL query
<font color="#000080">Format: $classVar-&gt;query(&quot;mysql query&quot;)</font></pre>
    <blockquote>
      <pre><font color="#0000cc">$paging</font><font color="#006600">-&gt;</font><font color="#0000cc">query</font><font color="#006600">(</font><font color="#cc0000">&quot;select * from paging order by MY_FIELD desc&quot;</font><font color="#006600">);
</font><font color="#0000cc">$paging</font><font color="#006600">-&gt;</font><font color="#0000cc">query</font><font color="#006600">(</font><font color="#cc0000">&quot;select * from paging where username='kentung' order by MY_FIELD desc&quot;</font><font color="#006600">);</font></pre>
    </blockquote>
    <pre><b>Step 5 [OPTIONAL]
</b>Page Information
<font color="#000080">Format: $classVar-&gt;print_info()</font>
Information about data result (start, end, total, total_pages, keyword)</pre>
    <blockquote>
      <pre><font color="#0000cc">$page</font><font color="#006600">=</font><font color="#0000cc">$paging</font><font color="#006600">-&gt;</font><font color="#0000cc">print_info</font><font color="#006600">();
</font><font color="#FF9900">/* generated :
$page[start]
$page[end]
$page[total]
$page[total_pages]
$page[keyword]
*/
</font><font color="#006600">echo&nbsp;<font color="#cc0000">&quot;Data&nbsp;$page</font>[<font color="#cc0000">start</font>]<font color="#cc0000">&nbsp;-&nbsp;$page</font>[<font color="#cc0000">end</font>]<font color="#cc0000">&nbsp;of&nbsp;$page</font>[<font color="#cc0000">total</font>]<font color="#cc0000">&nbsp;</font><font color="#006600">[</font><font color="#cc0000">Total&nbsp;$page</font>[<font color="#cc0000">total_pages</font>]<font color="#cc0000">&nbsp;Pages</font>]<font color="#cc0000">&lt;br&gt;</font>\n<font color="#cc0000">&quot;</font>;</font></pre>
    </blockquote>
    <pre><b>Step 6
</b><u>Fetch a result row as an object</u>
<font color="#000080">Format: $classVar-&gt;result()
</font>Place inside while looping</pre>
    <pre><u>Fetch a result row as an associative array</u><b>
</b><font color="#000080">Format: $classVar-&gt;result_assoc()
</font>Place inside while looping</pre>
    <pre><u>Random color [Optional]</u>
<font color="#000080">Format: $classVar-&gt;print_color(&quot;color1&quot;,&quot;color2&quot;)
</font>Place inside while looping</pre>
    <pre><u>Generate number [Optional]</u><font color="#000080"><b>
</b>Format: </font><font color="#000080">$classVar-&gt;print_no()
</font>Place inside while looping</pre>
    <blockquote>
      <pre><font color="#006600">while&nbsp;(</font><font color="#0000cc">$result</font><font color="#006600">=</font><font color="#0000cc">$paging</font><font color="#006600">-&gt;</font><font color="#0000cc">result</font><font color="#006600">(</font><font color="#006600">))
{
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000cc">$color</font><font color="#006600">=</font><font color="#0000cc">$paging</font><font color="#006600">-&gt;</font><font color="#0000cc">print_color</font><font color="#006600">(</font><font color="#cc0000">&quot;yellow&quot;</font><font color="#006600">,</font><font color="#cc0000">&quot;#FFCCCC&quot;</font><font color="#006600">)
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000cc">?&gt;
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;tr&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td width=&quot;3%&quot; bgcolor=&quot;<font color="#0000cc">&lt;?=$color?&gt;</font>&quot;&gt;<font color="#0000cc">&lt;?=$paging</font><font color="#006600">-&gt;</font><font color="#0000cc">print_no</font><font color="#006600">()</font><font color="#0000cc">?&gt;</font>&lt;/td&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;td width=&quot;98%&quot; bgcolor=&quot;<font color="#0000cc">&lt;?=$color?&gt;</font>&quot;&gt;<font color="#0000cc">&lt;?=$result</font><font color="#006600">-&gt;</font><font color="#0000cc">MY_FIELD?&gt;</font>&lt;/td&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/tr&gt;
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000cc">&lt;?
</font><font color="#006600">}</font></pre>
    </blockquote>
    <pre><b>Step 7</b>
Print next/prev
Format: $classVar-&gt;print_link()</pre>
    <blockquote>
      <pre><font color="#006600">echo&nbsp;</font><font color="#0000cc">$paging</font><font color="#006600">-&gt;</font><font color="#0000cc">print_link</font><font color="#006600">();</font></pre>
    </blockquote>
    <table border="0" width="100%" cellspacing="0" cellpadding="2" bgcolor="#008000">
      <tr>
        <td width="100%">
          <p align="center"><b><font color="#FFFFFF">-the end-</font></b></td>
      </tr>
    </table>
</body>
</html>
Return current item: Paging for MySQL