多表选择分页

时间:2015-12-26 14:40:20

标签: php

<!----------Connections--------->   
<?php define ("DB_HOST",
"localhost"); // Your database host name define ("DB_USER", "root");
// Your database user define ("DB_PASS",""); // Your database
password define ("DB_NAME","ideal"); // Your database name

$link = @mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't
make connection."); $db = @mysql_select_db(DB_NAME, $link) or
die("Couldn't select database"); ?>
    <!-------------Connections------------------------->    <?php
/********************************************

    For More Detail please Visit:   
    http://www.discussdesk.com/download-pagination-in-php-and-mysql-with-example.htm

    ************************************************/

   function displayPaginationBelow($per_page,$page){
       $page_url="?";
       $search='bhopal';
        $query = "SELECT COUNT(*) as totalCount FROM user_detail where city = '$search' or state = '$search' or country = '$search'";
        $rec = mysql_fetch_array(mysql_query($query));
        $total = $rec['totalCount'];
        $adjacents = "2"; 

        $page = ($page == 0 ? 1 : $page);  
        $start = ($page - 1) * $per_page;                               

        $prev = $page - 1;                          
        $next = $page + 1;
        $setLastpage = ceil($total/$per_page);
        $lpm1 = $setLastpage - 1;

        $setPaginate = "";
        if($setLastpage > 1)
        {   
            $setPaginate .= "<ul class='setPaginate'>";
                    $setPaginate .= "<li class='setPage'>Page $page of $setLastpage</li>";
            if ($setLastpage < 7 + ($adjacents * 2))
            {   
                for ($counter = 1; $counter <= $setLastpage; $counter++)
                {
                    if ($counter == $page)
                        $setPaginate.= "<li><a class='current_page'>$counter</a></li>";
                    else
                        $setPaginate.= "<li><a href='{$page_url}page=$counter'>$counter</a></li>";                  
                }
            }
            elseif($setLastpage > 5 + ($adjacents * 2))
            {
                if($page < 1 + ($adjacents * 2))        
                {
                    for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
                    {
                        if ($counter == $page)
                            $setPaginate.= "<li><a class='current_page'>$counter</a></li>";
                        else
                            $setPaginate.= "<li><a href='{$page_url}page=$counter'>$counter</a></li>";                  
                    }
                    $setPaginate.= "<li class='dot'>...</li>";
                    $setPaginate.= "<li><a href='{$page_url}page=$lpm1'>$lpm1</a></li>";
                    $setPaginate.= "<li><a href='{$page_url}page=$setLastpage'>$setLastpage</a></li>";      
                }
                elseif($setLastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
                {
                    $setPaginate.= "<li><a href='{$page_url}page=1'>1</a></li>";
                    $setPaginate.= "<li><a href='{$page_url}page=2'>2</a></li>";
                    $setPaginate.= "<li class='dot'>...</li>";
                    for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
                    {
                        if ($counter == $page)
                            $setPaginate.= "<li><a class='current_page'>$counter</a></li>";
                        else
                            $setPaginate.= "<li><a href='{$page_url}page=$counter'>$counter</a></li>";                  
                    }
                    $setPaginate.= "<li class='dot'>..</li>";
                    $setPaginate.= "<li><a href='{$page_url}page=$lpm1'>$lpm1</a></li>";
                    $setPaginate.= "<li><a href='{$page_url}page=$setLastpage'>$setLastpage</a></li>";      
                }
                else
                {
                    $setPaginate.= "<li><a href='{$page_url}page=1'>1</a></li>";
                    $setPaginate.= "<li><a href='{$page_url}page=2'>2</a></li>";
                    $setPaginate.= "<li class='dot'>..</li>";
                    for ($counter = $setLastpage - (2 + ($adjacents * 2)); $counter <= $setLastpage; $counter++)
                    {
                        if ($counter == $page)
                            $setPaginate.= "<li><a class='current_page'>$counter</a></li>";
                        else
                            $setPaginate.= "<li><a href='{$page_url}page=$counter'>$counter</a></li>";                  
                    }
                }
            }

            if ($page < $counter - 1){ 
                $setPaginate.= "<li><a href='{$page_url}page=$next'>Next</a></li>";
                $setPaginate.= "<li><a href='{$page_url}page=$setLastpage'>Last</a></li>";
            }else{
                $setPaginate.= "<li><a class='current_page'>Next</a></li>";
                $setPaginate.= "<li><a class='current_page'>Last</a></li>";
            }

            $setPaginate.= "</ul>\n";       
        }


        return $setPaginate;
    }  ?>







            <!---------------------Function---------------->    <?php   /********************************************

    For More Detail please Visit:   
    http://www.discussdesk.com/download-pagination-in-php-and-mysql-with-example.htm

    ************************************************/

    //Make Database connectivity




    if(isset($_GET["page"]))    $page = (int)$_GET["page"];     else    $page
= 1;

    $setLimit = 10;     $pageLimit = ($page * $setLimit) - $setLimit;

        ?>  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  <html
xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

    <head>  <title>Download Pagination in PHP and MySql With
Example</title>     <meta http-equiv="content-type" content="text/html;
charset=utf-8" />


    <style type="text/css">

    .show {     color: blue;    margin: 5px 0;  padding: 3px 5px;   cursor:
pointer;    font: 15px/19px Arial,Helvetica,sans-serif;     }   .show a {
    text-decoration: none;  }   .show:hover {   text-decoration:
underline;  }


    ul.setPaginate li.setPage{  padding:15px 10px;  font-size:14px;     }

    ul.setPaginate{     margin:0px;     padding:0px;    height:100%;
    overflow:hidden;    font:12px 'Tahoma';     list-style-type:none;       }  

    ul.setPaginate li.dot{padding: 3px 0;}

    ul.setPaginate li{  float:left;     margin:0px;     padding:0px;
    margin-left:5px;    }



    ul.setPaginate li a     {   background: none repeat scroll 0 0 #ffffff;
    border: 1px solid #cccccc;  color: #999999;     display: inline-block;
    font: 15px/25px Arial,Helvetica,sans-serif;     margin: 5px 3px 0 0;
    padding: 0 5px;     text-align: center;     text-decoration: none;  }   

    ul.setPaginate li a:hover,  ul.setPaginate li a.current_page    {
    background: none repeat scroll 0 0 #0d92e1;     border: 1px solid
#000000;    color: #ffffff;     text-decoration: none;  }

    ul.setPaginate li a{    color:black;    display:block;
    text-decoration:none;   padding:5px 8px;    text-decoration: none;  }




    </style>        </head>

    <body>

    <div class="navi">  <?php   $search='bhopal';

    $sql = "SELECT
lift,water,park,name,address,email,demand,property_size,property_location,about_property,city,state,country,property_image,cont_no
FROM user_detail where city = '$search' or state = '$search' or
country = '$search' LIMIT ".$pageLimit." , ".$setLimit;     $queryduser
= mysql_query($sql); $url=base_url('content/images/img/demand.png'); $size=base_url('content/images/img/size.png');
$location=base_url('content/images/img/location.png');
$about=base_url('content/images/img/about.png');
$basic=base_url('content/images/img/basic.png');
$features=base_url('content/images/img/features.png');
$tap=base_url('content/images/img/tap.png');
$park=base_url('content/images/img/park.png');
$lift=base_url('content/images/img/lift.png');
$contact=base_url('content/images/img/contact.png');
$owner=base_url('content/images/img/profile.png');
$blackheart=base_url('content/images/img/blackheart.png');
$redheart=base_url('content/images/img/redheart.png');

while($result=mysql_fetch_array($queryduser)) {


$name=$result['name']; $address=$result['address'];
$city=$result['city'];


$state=$result['state']; $country=$result['country'];
$mobile=$result['cont_no'];

echo "<table class='bgchange' ><tr><td>";



$image = $result['property_image'];


echo "<img src='$image' width='200px' height='150'>"."<br><img
src='$contact' title='View Contact Detail'  class='top'> <span
class='owner'> <img src='$owner' title='Owner Name' class='top'
></span><div id='contactowner' title='Contact Owner'><form method='get'>Owner Name :$name <br>Address :$address <br/> Mobile
Number :$mobile <br/>City : $city<br> State :$state<br/> Country
:$country</form><br><input type='button' class='button' value='View
more'></div></td> <td>";

echo"<div  class='topsearchbtn'style=''> <input type='button'
value='' class='button' /> <input type='button' value=''
class='button' /> <input type='button' value='' class='button' />
<input type='button' value='' class='button' /> <input type='button'
value='' class='button' /> <button  class='button'
style='width:100px;'>Map View <img src='$location'></button>
</div>";

echo "<img src='$basic'> Basic Detail
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: &nbsp;&nbsp; <img src='$url'>Price
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$result['demand']."| &nbsp;&nbsp;
<img src='$size'>Size
&nbsp;".$result['property_size']."|&nbsp;&nbsp; <img
src='$location'>Location &nbsp;".$result['property_location']."|";

 echo "<br/>"; echo "<img src='$features'> Features
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:  <img
src='$tap'> Water Storage &nbsp;".$result['water']."| &nbsp;&nbsp;
<img src='$park'> Park &nbsp;".$result['park']."|&nbsp;&nbsp; <img
src='$lift'> Lift &nbsp;".$result['lift']."|";




 echo "<br/>";  echo "<img src='$about'> About Property 
:".$result['about_property']."<br/>";  echo "City
:".$result['city']."<br/>";   echo "State
:".$result['state']."<br/>";   echo "Country
:".$result['country']."<br/>";   echo"<script
type='text/javascript'>   $('document').ready(function(){  
$('.contact').click(function(){ $( '.div' ).show(); }); 
$('.div').mouseover(function(){ $( '.div' ).show(); }); 
$('.div').mouseout(function(){ $( '.div' ).hide(); }); 
$('.div').mouseout(function(){ $( '.div' ).hide(); });

});
    </script>   <style type='text/css'>   .div:hover{color:#ffffff;   background-color:#475c4d;
     }
     </style>
     ";   echo"<style type='text/css'> .div{width:270px;background-color:#ffffff;height:200px;display:none;position:absolute;color:#000;border:1px
solid #bcbcbc;border-radius:4px;}</style>";   echo "<input
type='button' class='button contact' value='Contact Owner' class=''
style='width:135px;'/> <input type='button'
class='button'style='width:135px;' value='Report Problem
Listing'><div class='div'>Owner Name : $name <br/> Contact Number :
$mobile <br/>Address : $address<br/> City :$city<br/>State : $state
<br> Country :$country<br/><input type='button' value='more'
class='button'style='width:40px;'><br><a href=''>By clicking this
you agree to Terms and conditions.</a></div> <img src='$blackheart'
class='shortlist1' Title='Shortlisted'><img src='$redheart'
class='shortlist2' Title='Shortlisted'>"; 
$result['cont_no']."</td></tr>";

echo"</table><br><hr>"; //This was for city
admin.............................................//










}   ?>  </div>

    <?php   // Call the Pagination Function to load Pagination.

    echo displayPaginationBelow($setLimit,$page);   ?>


<script type="text/javascript">

  var _gaq = _gaq || [];   _gaq.push(['_setAccount',
'UA-38304687-1']);   _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);   })();

</script>

0 个答案:

没有答案