Jump to content

pagination pages are blank


Magadlamp

Recommended Posts

I get my results when I search kul. I paged my search results but now all my pages come blank when I click the page number to navigate to. I can't navigate from page one or back to page ,1plz help.

 

here is my code

 

----------------------CODE--------------------------

    <?php

$output = '';

# used in pagination--------------------

$per_page = 2 ;

#---------------------------------------

                 if (isset($_POST['search']) and isset($_POST['search2']))

                 {

                                $searchq = $_POST['search'];

                                $searchq = preg_replace("#[^0-9a-z]#i","",$searchq);

                               

                                $searchq2 = $_POST['search2'];

                                $searchq2 = preg_replace("#[^0-9a-z]#i","",$searchq2);

 

                               

                                # used in pagination--------------------

                                $pages_query = mysql_query("SELECT COUNT('id') FROM provider_info  "); //counting the number of records in a search

                                $pages = ceil(mysql_result($pages_query, 0) / $per_page);

                                $page = (isset($_GET['page'])) ?(int)$get['GET'] :1;

                                $start = ($page - 1) * $per_page;

                               

                                #---------------------------------------

                                $query = mysql_query("SELECT * FROM provider_info WHERE(Business_Name LIKE '%$searchq%'AND Services LIKE '%$searchq2%')OR (Address_Ln1 LIKE '%$searchq%'AND Services LIKE '%$searchq2%')OR (Suburb LIKE '%$searchq%'AND Services LIKE '%$searchq2%')OR (Town LIKE '%$searchq%'AND Services LIKE '%$searchq2%') LIMIT $start,$per_page") or die("Could not search");

                                $pages_query = mysql_num_rows($query);

                                if ($pages_query ==0)

                                {

                                                $output = 'There were no search results found';

                                } else

                                {

                                                while($row = mysql_fetch_assoc($query))

                                                {

                                                                $bName = $row ['Business_Name'];

                                                                $aAddress_Ln1 = $row ['Address_Ln1'];                                                               

                                                                $cContact_No = $row['Contact_No'];    

                                                                $sSuburb = $row['Suburb'];

                                                                $tTown = $row['Town'];

                                                                $lLink = $row['Link'];

                                                                $dDescription = $row['Description'];

                                                                $pPicture = $row['Picture'];                        

                                                                $output.= '<div>'.$bName.''.$cContact_No.''.$aAddress_Ln1.''.$sSuburb.''.$tTown.''.$lLink.''.$dDescription.''.$pPicture.'</div>';

                               

                                 echo     "

                                                                <table  border=1 cellspacing =5>

                                                                <tr><td colspan =6 align = center><h2>{$bName}</h2></td></h2> </tr>

                                                                <tr><td rowspan = 6 width = 300>I am going to place an image here</td><td width = 90 align=right>

                                                                <b>Business Name</b></td><td width = 120>{$bName}</td><th colspan = 3 align = right colspan = 3><font color=#f90 align=right>Business Description</font></th> ".

                                        "<tr><td align=right><b>Contact No</b></td><td>{$cContact_No}</td><td rowspan = 5 colspan = 3 align = left width = 220><font color=#f90>{$dDescription}</font></td>".

                                        "<tr><td align=right><b>Address</b></td><td>{$aAddress_Ln1}</td>".

                                        "<tr><td align=right><b>Suburb</b></td><td>{$sSuburb}</td>".

                                        "<tr><td align=right><b>Town</b></td><td>{$tTown}</td>".

                                        "<tr><td align=right><b>Email</b></td> <td>{$lLink}</td>".

                                        "<tr><td>{$pPicture}</td>".

                                "<tr><td colspan = 6>__________________________________________________________________________________________________________________</td><br></table>";

                                                               

                                                               

#                                                             $output .= '<div>'.$bname.''.$aAddress_Ln1.'</div>';

                                                }

# used in pagination--------------------

$prev = $page - 1;

$next = $page + 1;          

if (!($page <= 1))

{

                echo "<a href='results.php?page=$prev'>Prev</a> ";

}

                 }

                 if ($pages >=1)

                 {

                                 for($x =1; $x <= $pages; $x ++)

                                 {

                                                echo ($x == $page) ? '<b><a href=?page='.$x.'>'.$x.'</a></b> ' : '<a href=?page='.$x.'>'.$x.'</a> ';

                                 }

                 }

if (!($page >= $pages))

{             

echo "<a href='results.php?page=$next'>Next</a> ";

}

print("$pages_query");

#---------------------------------------------------

}

?>

--------------------CODE END-------------------

 

Thanks now

New PHP Learner

Link to comment
Share on other sites

Data contained in $_POST is not remembered between page requests. So when you go click one of your pagination links from the search results the data in $_POST will no longer exists and so no results are displayed resulting. Which is probably why you get a blank page.

 

To prevent this you could save the search data from $_POST to a session. Then when a page is requested you get the search data from the session and not from $_POST. First start by adding   session_start();   so its after the opening PHP tag <?php

 

Then change this code

if (isset($_POST['search']) and isset($_POST['search2']))
{
    $searchq = $_POST['search'];
    $searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
   
    $searchq2 = $_POST['search2'];
    $searchq2 = preg_replace("#[^0-9a-z]#i","",$searchq2); 

to

if (isset($_POST['search']) and isset($_POST['search2']))
{
    $searchq = $_POST['search'];
    $searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
   
    $searchq2 = $_POST['search2'];
    $searchq2 = preg_replace("#[^0-9a-z]#i","",$searchq2);

    // Add search data to session. This is so it can be persisted between page requests
    $_SESSION['searchq'] = $searchq;
    $_SESSION['searchq2'] = $searchq2;
}

// if a page is requested. Get the search data back from the session
if(isset($_GET['page']))
{
    $searchq  = $_SESSION['searchq'];
    $searchq2 = $_SESSION['searchq2'];
}

// Perform the search if we have the search data
if(isset($searchq) && isset($searchq2))
{

The alternative would be to pass the search data in your pagination links.

Edited by Ch0cu3r
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.