Hello there.. I am currently working with the referral program and I have a page wherein it displays all the personal information of a person who referred by the user login.. I have 2 functions for displaying the records.. Number 1 is just displaying the records when you go to the view page and Number 2 is a search function so you can easily see specific person you wanted to see.
The problem I encounter is, when I type in the search box, definitely my function to search is the one who responsible for displaying some specific records.. I add pagination so that if the record is more than 10, User can still able to view the other records by clicking page 2 but the problem is when I click the page 2 or search result page pagination. The records didn't display on page 2 and its pagination change into the original once I click page2 or the next and previous button` Here is my forum for search

<!-- Here goes the Search Area -->
        <div class="twelve columns">
            <div class="search">
                <div class="searchbox">
                    <div id="form-container"> 
                            <div id="searchtext">
                            <form name="formSearch" method="GET" action="view_referral.php" >
                            <button class="gobtn">Search</button>
                            <input type = "text" id="s" name="searchField" size="25" placeholder="Search referrals...">
                            <input type ="submit" name="searchButton" value="Search" style="display:none;">


                        </form>
                            </div>
                    </div>
                </div>
            </div>
        </div>



<!-- Here the Main Content goes -->
            <div class="twelve columns">
                <div class="content">
                    <span class="referralstatus">
                        <div class="totalreferral">
                            Total referrals<p><?php include('../function/func_countTotalReferredLeads.php');?></p>
                        </div>
                        <div class="totalhires">
                            Total Hires<p><?php include('../function/func_countHiredReferrals.php');?></p>
                        </div>
                        <div class="failed">
                            Failed<p><?php include('../function/func_countFailedReferrals.php');?></p>
                        </div>
                    </span>

                    <span class="profile">
                            <div class="refereeprofile">
                            <p align="center" class="refereetitle">REFERRAL INFORMATION</p>
                                <div class="employeeinfo">
                                    <div class="empn">
                                        <p align="left" class="employeename"><strong>Employee ID:<span class="empnn"><?php echo $empid; ?></span></p>
                                    </div>
                                    <div class="empid">
                                        <p align="left" class="employeeid"><strong>Employee Name:<span class="empdd"><?php echo $firstname .' '. $lastname;?></span></p>
                                    </div>
                                </div>



                                <div class="accessinfo">
                                    <div class="accd">
                                        <p align="left" class="accessdate"><strong>Access Date:  <?php echo $current_date;?></p>
                                    </div>
                                    <div class="acct">
                                        <p align="left" class="accesstime"><strong>Access Time: <?php echo $current_time;?></p>
                                    </div>
                                </div>
                            </div>

                            <div class="referentprofile"> 
                                <p>List of Referrals</p>
                                <table class="u-full-width">
                                    <tr>
                                    <td><strong>Lead No.<strong></td>
                                    <td><strong>Referral Name</strong></td>
                                    <td><strong>Date Referred</strong></td>
                                    <td><strong>Mobile Number</strong></td>
                                    <td><strong>Email Address</strong></td>
                                    <td><strong>Call Status</strong></td>
                                    <td><strong>Application Status</strong></td>
                                    </tr>
                                <?php

                            $_SESSION['SESS_PAGE'] = $_SERVER['PHP_SELF'];

                            // Change this during actual system run
                            if (empty($_GET['searchField'])){
                            include('../function/func_testPopulateLeads.php');
                                    }
                                    else {
                                        include('../function/func_testSearchByName.php');
                                        } 

                            ?>

                        </table>
                                </div>
                            <center>
                            <div style="text-align: center;">
                        <?php 
                        include('../function/func_pagination_new.php'); 
                        ?>
                        <?=$pagination?>
                    </div>
                    </center>    
                    </span>
                </div>
            </div>

        <!-- Here the Reminder goes -->
        <center>
            <div class="recordshown">

                <div class="twelve columns"> 

                    <p align="justify">
                    <?php echo 'Total Records Shown: ' . $_POST['data_num_row']; ?>  *** If you know any information from above that needs to be corrected, please contact us.</p>
                    <?php

                    $total_rows = $_SESSION['SESS_QRYTOTALROWS'];   
                    $data_num = $_POST['data_num_row'];
                if($data_num == 0)
                    {
                    echo '<div id="result">Message: No Record/s Found!</div>';
                    }
                elseif ($total_rows != 0)
                    {
                    echo '<div id="result">End of Results from Current Query...</div>';
                    } 
                elseif($data_num != 0)
                    {
                    echo '<div id="result">End of Results from Current Query...</div>';
                }                                   
                elseif ($total_rows > 15)                   
                    {
                    echo $pager->renderFullNav();
                    }
                else
                    {
                    echo '<div id="result">Message: No Record/s Found!</div>';
                    echo '<div id="result">*End of Result...</div>';
                    }
                ?>

                </div>
            </div>
            </center>

Here is my pagination

<?php
/* Setup page vars for display. */
    if ($page == 0) $page = 1;                  //if no page var is given, default to 1.
    $prev = $page - 1;                          //previous page is page - 1
    $next = $page + 1;                          //next page is page + 1
    $lastpage = ceil($total_pages/$limit);      //lastpage is = total pages / items per page, rounded up.
    $lpm1 = $lastpage - 1;  
                        //last page minus 1
    /*
        Now we apply our rules and draw the pagination object. 
        We're actually saving the code to a variable in case we want to draw it more than once.
    */
        $pagination = "";
        if($lastpage > 1)
        {   
            $pagination .= "<div class=\"pagination\">";
        //previous buttons
            if ($page > 1) 
                $pagination.= "<a class='buttons' href=\"$targetpage?page=$prev\">previous</a>";
            else
                //$pagination.= "<a class='disabled'><buttons disabled>previous</buttons></a>"; 
                $pagination.= "<a class='buttons'>previous</a>";

        //pages 
        if ($lastpage < 4 + ($adjacents * 2))    //not enough pages to bother breaking it up
        {   
            for ($counter = 1; $counter <= $lastpage; $counter++)
            {
                if ($counter == $page)
                    $pagination.= "<a class='current'><buttons style='background-color:#CEF6F5'>$counter</buttons></a>";
                else
                    $pagination.= "<a class='buttons' href=\"$targetpage?page=$counter\">$counter</a>";                   
            }
        }
        elseif($lastpage > 1 + ($adjacents * 2))    //enough pages to hide some
        {
            //close to beginning; only hide later pages
            if($page < 1 + ($adjacents * 2))     
            {
                for ($counter = 1; $counter < 3 + ($adjacents * 2); $counter++)
                {
                    if ($counter == $page)
                        $pagination.= "<a class='current'><buttons style='background-color:#CEF6F5'>$counter</buttons></a>";
                    else
                        $pagination.= "<a class='buttons' href=\"$targetpage?page=$counter\">$counter</a>";                   
                }
                $pagination.= "...";
                //$pagination.= "<a class='buttons' href=\"$targetpage?page=$lpm1\">$lpm1</a>";
                $pagination.= "<a class='buttons' href=\"$targetpage?page=$lastpage\">$lastpage</a>";     
            }
            //in middle; hide some front and some back
            elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
            {
                $pagination.= "<a class='buttons' href=\"$targetpage?page=1\"> 1 </a>";
                //$pagination.= "<a class='buttons' href=\"$targetpage?page=2\"> 2 </a>";
                $pagination.= "...";
                for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
                {
                    if ($counter == $page)
                        $pagination.= "<a class='current'><buttons style='background-color:#CEF6F5'>$counter</buttons></a>";
                    else
                        $pagination.= "<a class='buttons' href=\"$targetpage?page=$counter\">$counter</a>";                   
                }
                $pagination.= "...";
                //$pagination.= "<a class='buttons' href=\"$targetpage?page=$lpm1\">$lpm1</a>";
                $pagination.= "<a class='buttons' href=\"$targetpage?page=$lastpage\">$lastpage</a>";     
            }
            //close to end; only hide early pages
            else
            {
                $pagination.= "<a class='buttons' href=\"$targetpage?page=1\">1</a>";
                //$pagination.= "<a class='buttons' href=\"$targetpage?page=2\">2</a>";
                $pagination.= "...";
                for ($counter = $lastpage - (2 + ($adjacents * 1)); $counter <= $lastpage; $counter++)
                {
                    if ($counter == $page)
                        $pagination.= "<a class='current'><buttons style='background-color:#CEF6F5'>$counter</buttons></a>";
                    else
                        $pagination.= "<a class='buttons' href=\"$targetpage?page=$counter\">$counter</a>";                   
                }
            }
        }

        //next buttons
        if ($page < $counter - 1) 
            $pagination.= "<a class='buttons' href=\"$targetpage?page=$next\">next</a>";
        else
            $pagination.= "<a class='buttons'>next</a>";
        $pagination.= "</div>\n";        
    }


    ?>

Here is my function searching specific name

<?php

        Place code to connect to your DB here.
    */
include('../include/dbconnection.php'); // include your code to connect to DB.


$firstname = $_SESSION['SESS_FIRSTNAME'];
$lastname = $_SESSION['SESS_LASTNAME'];
$bdate= $_SESSION['SESS_BDAY'];

$tbl_name="vtiger_leaddetails"; //your table name
// How many adjacent pages should be shown on each side?
$adjacents = 1;

    /* 
       First get total number of rows in data table. 
       If you have a WHERE clause in your query, make sure you mirror it here.
    */
 $query1 = "SELECT COUNT(*) as num FROM $tbl_name INNER JOIN 
       vtiger_leadscf
       ON vtiger_leaddetails.leadid = vtiger_leadscf.leadid
       INNER JOIN vtiger_leadaddress
       ON vtiger_leadaddress.leadaddressid = vtiger_leadscf.leadid
       INNER JOIN vtiger_crmentity
       ON vtiger_crmentity.crmid = vtiger_leadaddress.leadaddressid
       WHERE 
      (CONCAT(vtiger_leaddetails.firstname, ' ', vtiger_leaddetails.lastname) LIKE '%" . $_GET['searchField'] ."%' 
        AND vtiger_leadscf.cf_823 = '".$firstname."'
        AND vtiger_leadscf.cf_825 = '".$lastname."'
        AND vtiger_leadscf.cf_1057 = '".$bdate."'
        AND vtiger_crmentity.deleted <> 1
        AND vtiger_leadscf.cf_1039 is null
        )
ORDER BY
    vtiger_leadscf.cf_831 DESC
    " ;

$total_pages = mysql_fetch_array(mysql_query($query1));
$total_pages = $total_pages[num];

 $_SESSION['SESS_QRYTOTALROWS']=$total_pages;

/* Setup vars for query. */
    $targetpage = $_SESSION['SESS_PAGE'];   //your file name  (the name of this file)
    $limit = 8;                                 //how many items to show per page
    $page = $_GET['page'];
    if($page) 
        $start = ($page - 1) * $limit;          //first item to display on this page
    else
        $start = 0;     

$query = 
"SELECT 
    vtiger_leaddetails.lead_no,
    vtiger_leaddetails.firstname,
    vtiger_leadscf.cf_779,
    vtiger_leaddetails.lastname,
    vtiger_leadscf.cf_831,
    vtiger_leadaddress.mobile,
    vtiger_leaddetails.email,
    vtiger_leadscf.cf_885,
    vtiger_leaddetails.leadstatus
FROM 
    vtiger_leaddetails 
INNER JOIN 
    vtiger_leadscf
ON 
    vtiger_leaddetails.leadid = vtiger_leadscf.leadid
INNER JOIN 
    vtiger_leadaddress
ON 
    vtiger_leadaddress.leadaddressid = vtiger_leadscf.leadid
INNER JOIN vtiger_crmentity
ON vtiger_crmentity.crmid = vtiger_leadaddress.leadaddressid
WHERE 

     (CONCAT(vtiger_leaddetails.firstname, ' ', vtiger_leaddetails.lastname) LIKE '%" . $_GET['searchField'] ."%' 
    AND vtiger_leadscf.cf_823 = '".$firstname."'
    AND vtiger_leadscf.cf_825 = '".$lastname."'
    AND vtiger_leadscf.cf_1057 = '".$bdate."'
    AND vtiger_crmentity.deleted <> 1
    AND vtiger_leadscf.cf_1039 is null

    )

ORDER BY
    vtiger_leadscf.cf_831 DESC

LIMIT $start, $limit
" ;


$result = mysql_query($query)or die(mysql_error());
$_POST['data_num_row']=  mysql_num_rows($result);
while($row = mysql_fetch_assoc($result)) {
    $td_leadno = $row['lead_no'];
    $td_reffname = $row['firstname'];
    $td_refmname = $row['cf_779'];
    $td_reflname= $row['lastname'];
    $td_dateref = $row['cf_831'];
    $td_mobile = $row['mobile'];
    $td_email = $row['email'];
    $td_callstatus = $row['cf_885'];
    $td_leadstatus = $row['leadstatus'];

    echo '
    <tbody>
    <td>'.$td_leadno.'</td>
    <td>'.$td_reffname.' '.$td_refmname.' '.$td_reflname.'</td>
    <td>'.$td_dateref.'</td>
    <td>'.$td_mobile.'</td>
    <td>'.$td_email.'</td>
    <td>'.$td_callstatus.'</td>
    <td>'.$td_leadstatus.'</td>
    </tbody>
    ';
}
    ?>

The problem occurs in pagination when I type some specific names in the search box and for example if this name has more than 10 records, it should definitely have a pagination.. Can someone help me why when I type in the search box and for example it has 50 records. When I click the page 2 or next button. The records won't display and the pagination change to original output of it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.