Three if condition
if(isset($_POST['search']) & !empty($_POST['searchdata']) )

if(isset($_POST['search']) & !empty($_POST['searchName']) )

Else
each statement have the own pagination created now confusion for example first condition is true and three page is created when i click its goes to else condition and below 10 pages is created which is true in else condition..how to handle the click of page to go to their respective condition

Sorry, I guess I don’t understand your question. You have a series of if statements that check for certain conditions passed into a form. I’m not sure how that relates to pagination? What code for pagination do you have so far?

means for first condition 3 pages is created and when i click page1..it should go to page1 and below same 3 pages in pagination should show but when i click it goes to else condition and 12 pages is shows in pagination section.
how to control search condition with pagination clicking

It's a PHP Self statement on the same Page right? I worked on a Project 2days ago and used the same method, i prefer making buttons for it and fill the value of it as the statement (i prefer using switch for this) and sorry if my answer is not relevant, i kind of don't get your question but i hope it's right :)

$statement  = $_POST['submit'];
$searchData = $_POST['searchdata'];
$searchName = $_POST['searchName'];


if(!empty($searchData) || !empty($searchName))
{
    switch($statement)
    {
        case "search_data":
        {
            //code here
        }
        break;
        case "search_name":
        {
            //code here
        }
        break;
    }
}
else
{
    //code here
}

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
    <button type="submit value="search_data">Search Data</button>
    <button type="submit value="search_name">Search Name</button>
</form>

thanks for your reply i rephrase yours answer as look at the pagination code there is 3 pages and 2 pages and 10 pages total means when no search condition is given it created 10 pages but problem is when ist condition is true and in result bottom of 3 pages is created and when i click one of my page data is refresh but in bottom pagination is gone to 10 while it should restrict to similarity when 2nd condition is true 2 pages is created and when i click one of two pages , data is refresh correctly but but in bottom the pagination is gone to 10......my question is how i can restrict the pagination along with the data

                    if(!empty($searchData) || !empty($searchName))
                         case "search_data":{
                            //code here
          //code for pagination for example 3 pages is created in this condition
            }
            break;
            case "search_name":
            {
                //code here
                 //code for pagination for example 2 pages is created in this condition
            }
            break;
        }

    else
    {
        //code here
         //code for pagination for example 10 pages is created in this condition
    }
    }
    <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
        <button type="submit value="search_data">Search Data</button>
        <button type="submit value="search_name">Search Name</button>
    </form>

Do you already have the pages available? or do you not have them yet, If you do then you can use the readfile or file_get_contents on the specified switch case. If you don't have the files you can make a function that renders the html page.

  1. If you have the HTML Available for you you can either use readfile or file_get_contents (big files will most likely crash)

     if(!empty($searchData) || !empty($searchName))
     {
         switch($_ISSET['submit'])
         {
             case "search_data":
             {
                 //code here
                 readfile("Page1");
                 readfile("Page2");
                 readfile("Page3");
                 //code for pagination for example 3 pages is created in this condition
             }
             break;
             case "search_name":
             {
                 //code here
                 readfile("Page1");
                 readfile("Page2");
                 //code for pagination for example 2 pages is created in this condition
             }
             break;
         }
     }
     else
     {
         //code here
         //code for pagination for example 10 pages is created in this condition
     }
    
     <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
         <button type="submit value="search_data">Search Data</button>
         <button type="submit value="search_name">Search Name</button>
     </form>

If you do not have HTML File available for you you can render your code through a PHP Function

i have simplest my question here is code

//link to pass the value searchdata='bilal' url of  page
//this is pagenation code when click
echo '<li class="'.$active.'" ><a class="page-link" href="manage_visitor.php?page1='.$i.'&searchname='.$_POST['searchdata'].'">'.$i.'</a></li>';
when i click on the any page url look like this
http://localhost/company/manage_visitor.php?page=2&searchname=bilal
which is working correctly but when i click again on any page the url look like this
http://localhost/company/manage_visitor.php?page1=2&searchname=
searchname is empty how i can store the value in searchname upto reset button is not click 

You can try making a Handler for it that works dynamically, an easy way to make it work based on my experience is either use http build query, or manually passing to the next page by extracting the $_GET values to the href (code below). And Put a PHP function on the top of the page to look something like this if you want to do extra (if not you can ignore because there are various methods)

For your problem where the searchname is not passed is because searchname is a $_POST value, which means it needs an identical Submit button to be pressed, so in order to do that

echo '<li class="'.$active.'" ><a class="page-link" href="manage_visitor.php?page1='.$i.'&searchname='.$_GET['searchdata'].'">'.$i.'</a></li>';

use $_GET instead of $_POST, unless you're clicking it through a form

This will get the value of searchname to be passed to let's say Page is 4 moving to 5, with the searchname Value as John,

then the href would return manage_visitor.php?page1=5&searchname=John

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.