Pagination of Search Results

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
emilcarlo
Forum Commoner
Posts: 43
Joined: Wed Jul 21, 2010 12:38 pm

Pagination of Search Results

Post by emilcarlo »

Good Evening,
I've been in a trial and error state for the past week trying to figure out how I can put on the pre-made pagination scripts I found on the web, but of no luck. I have just started programming like two weeks ago, and is still trying to understand logics and stuffs so I can get my desired output. So far, everything is doing well except for one - I am really having a hard time to incorporate pagination scripts with my code. To rank myself as a php programmer, I can say I am lower than one, and seemingly, what I want to achieve is an advanced code. Can anyone help me on what pagination code I should try to play with and incorporate with my code?

Here's my code so far:

Code: Select all

<?PHP
include("dbconnection.php"); //Include database connection to file

$query = "SELECT * FROM records";

if(isset($_POST["btnSearch"]))

	

{

	

	

$query .= " WHERE last_name LIKE '%".$_POST["search"]."%' OR first_name LIKE '%".$_POST["search"]."%'OR territory LIKE '%".$_POST["search"]."%'OR job_title LIKE '%".$_POST["search"]."%'OR title LIKE '%".$_POST["search"]."%'OR employer LIKE '%".$_POST["search"]."%' ORDER BY territory ASC LIMIT 0,15"  ;

	

	


	

	

$result = mysql_query($query, $connection) or die(mysql_error());

	

} 

?>

<!-- Start of table -->
<table width="760" border="0" align="center" cellpadding="0" cellspacing="0">

	

<td>
      <table width="760" border="0" cellpadding="0" cellspacing="0">
        

	

	

	

<!-- Table data containing the Asia Logo -->
            <td width="199" align="center" valign="top">
                <a href="login.html">
                

	

<img src="asia.gif" alt="" width="152" height="58" border="0" />
                </a>
            </td>
            <!-- Table data containing Home button -->
            <td width="176" align="right" valign="bottom">
                <a href="main.php">
                

	

<img src="Home.jpg" width="104" height="20" border="0"/>
                </a>
            </td>
            <!-- Table data containing View Client button -->
            <td width="130" align="right" valign="bottom">
                <img src="View.jpg" width="104" height="20" border="0"/>
            </td>
            <!-- Table data containing the Add Client button -->
            <td width="146" align="right" valign="bottom">
                <a href="add_client.php">
                

	

<img src="Add.jpg" width="104" height="20" border="0"/>
                </a>
            </td>
            <!-- Blank table data -->
            <td width="109" align="right" valign="bottom">&nbsp;
            

	


            </td>
        </table>

        <!-- Table design division and body-->
        <table width="760" border="0" cellpadding="0" cellspacing="0">
    

	

	

<td width="200" height="3"  bgcolor="#1B1C78">
    

	

	

	

<img src="images/topspacerblue.gif" alt="" width="1" height="3" /></td>
   

	

	

	

<td width="560"  bgcolor="#0076CC">
    

	

	

	

<img src="images/topspacerlblue.gif" alt="" width="1" height="3" /></td>

	

	

    <tr>

	

	

    <td height="500" colspan="2" align="center" valign="top"  bgcolor="#F3FAFE">
            <!-- Page contents -->
            <!-- Search Query -->
            <br>
            <form name="form" action="view_client.php" method="post">
            <table width="351" border="0">

	

	

	

	

<tr>
                    <td width="137" align="left" valign="middle">
                        SEARCH RECORD:
                    </td>
                    <td width="144" align="center" valign="middle">
                        <input type="text" name="search" />
                    </td>
                    <td width="56" align="left" valign="middle">
                        <input type="submit" name="btnSearch" value="Search" />
                    </td>

	

	

	

	

</tr>

	

	

	

</table>
            <br>
            <!-- End of search query-->
            <!-- Start of Search Results-->

	

	

	


            <table border="0" cellpadding="3" cellspacing="1" bordercolor="38619E" >
                <tr>
                    <th width="80" align="center" bgcolor="#E0E8F3">Territory</th>
                    <th width="330" align="center" bgcolor="#E0E8F3">Employer</th>
                    <th width="160" align="center" bgcolor="#E0E8F3">Name</th>
                    <th width="80" align="center" valign="middle" bgcolor="#E0E8F3">&nbsp;</th>
                </tr>
<?php

	

if($result)

	

	

{

	

	

	

for($i=0; $i<mysql_num_rows($result); $i++)

	

  

	

	

	

{

	

	

	

	

	

$id = trim(mysql_result($result, $i, "id"));

	

	

	

	

	

$territory = trim(mysql_result($result, $i, "territory"));

	

	

	

	

	

$employer = trim(mysql_result($result, $i, "employer"));

	

	

	

	

	

$first_name = trim(mysql_result($result, $i, "first_name"));

	

	

	

	

	

$last_name = trim(mysql_result($result, $i, "last_name"));

	

	

	

	

	

	

  

	

	

	

	

	

echo "<tr>";

	

	

	

	

  

	

echo "<td>".$territory."</td>";

	

	

	

	

  

	

echo "<td>".$employer."</td>";

	

	

	

	

  

	

echo "<td>".$last_name.", ".$first_name."</td>";

	

	

	

	

  

	

echo "<td><a href='edit_client.php?id=".$id."'>edit</a> | <a href='delete_client.php?id=".$id."'>delete</a></td>";

	

	

	

	

  

	

echo "</tr>";

	

	

	

	

}

	

  

	

	

}  
?>

	

	

	

</table>
            </form>
            <!-- End of page -->
           

	

</td>
          </tr>
        </table>

	

</td>

	

<tr>
    

	

<td height="38">
        

	

<table width="760" border="0" cellpadding="0" cellspacing="0">      
        

	

	

<td width="200" height="35" align="center"  bgcolor="#1B1C78" class=white>
        

	

	

	

<a href="disclaimer.html">
            

	

	

	

<font color="#FFFFFF">Legal Disclaimer</font>
            

	

	

</a>
        

	

	

</td>
        

	

	

<td width="560" align="center"  bgcolor="#0076CC">
        

	

	

	

Copyright &copy; 2006 - 2010 Asia. All rights reserved.
        

	

	

</td>

	

	

</table></td>

	

</tr>
</table>
Thank you very much, and I am looking forward for your responses. Thanks!
Post Reply