Saturday, 21 December 2013

Page has to be refreshed



Page has to be refreshed or after a certain period of seconds

Lekhulal 
lekhulkal@gmail.com
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<meta http-equiv="refresh" content="value">

Include the above mentioned meta tag, inside of <head> tag 

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

For example :

<html>
     <head>
          <meta http-equiv="refresh" content="10"> /Every 10Secp age will be refreshed
     </head>
     <body>
          <!-- code hete... -->
     </body>
</html>
------------------------------------------------------------------Thank you----------------------------------------------------------------

Thursday, 19 December 2013

Solution for repeating result in SQL

Solution for repeating result

 Arya P Ramesan

-----------------------------------------------------------

SQL query: SELECT p.job_post_id ,pl.location_id FROM tbl_employer_post_details p INNER JOIN tbl_employer_post_location pl ON p.job_post_id=pl.job_post_id LIMIT 0, 30 ;

Rows: 16

job_post_id
location_id
post1
LO1
post1
LO2
post1
LO3
post1
LO4
post2
LO3
post2
LO4
post2
LO1
post2
LO2
post3
LO2
post3
LO4
post4
LO5
post4
LO1
post5
LO1
post5
LO5
post6
LO3
post6
LO5

Solution


SQL query:
SELECT p.job_post_id ,GROUP_CONCAT(pl.location_id) location_ids FROM tbl_employer_post_details p INNER JOIN tbl_employer_post_location pl ON p.job_post_id=pl.job_post_id GROUP BY p.job_post_id LIMIT 0, 30 ;

Rows: 6

job_post_id
location_ids
post1
LO1,LO2,LO3,LO4
post2
LO3,LO4,LO1,LO2
post3
LO2,LO4
post4
LO5,LO1
post5
LO1,LO5
post6
LO3,LO5

Pagination using PHP Mysqli MVC Stored procedure

Pagination using PHP Mysqli MVC Stored Procedure

-Lekhulal 
Email: lekhulal@gmail.com
  ------------------------------------------------------------------------------------------------------------------------

Database     :          db_state
Table name :          states
Feild-name :
                               id
                               name

  ------------------------------------------------------------------------------------------------------------------------

Stored procedure :
 
DELIMITER //
CREATE DEFINER=`root`@`localhost` PROCEDURE `get_statenames`()
begin
select name from states;
end //

DELIMITER ;


  ------------------------------------------------------------------------------------------------------------------------
DELIMITER // 
CREATE DEFINER=`root`@`localhost` PROCEDURE `get_state_limit`(IN start int,
IN  max int
)
begin
select * from states LIMIT start, max;
end //
DELIMITER ;
  ------------------------------------------------------------------------------------------------------------------------

Pagination/model/database_connection.php :


<?php
    class Database_connection
    {
        public function new_connection()
        {
            $mysqli     =   new mysqli('localhost','root','password','db_state');   
            return $mysqli;
         }
    }
?>


  ------------------------------------------------------------------------------------------------------------------------

Pagination/view/index.php :

<?php
     require_once '../model/service_class.php';
     $obj    =    new Service_class();
     $res    =    $obj->select_names();
     /* Set current, prev and next page */
     $page = (!isset($_GET['page']))? 1 : $_GET['page'];

     $prev = ($page - 1);
     $next = ($page + 1); /* Max results per page */
     $max_results = 3;  /* Calculate the offset */
     $start = (($page * $max_results) - $max_results);           
                     if($res)
                       {
                        $result_user=$mysqli->store_result();            
                        $total_results = mysqli_num_rows($result_user);
                        $total_pages = ceil($total_results / $max_results);
                    
                                        $result_user->free();
                                        while($mysqli->next_result())
                                           {
                                                $result_user=$mysqli->use_result();
                                                 if($result_user instanceof mysqli_result)
                                                {
                                                   $result_user->free();
                                                }
                                           }  
                      $result=$obj->select_state_limit($start, $max_results);               
                      }
                                            if($page > 1)
                    {
                   ?>
                      <a href="index.php?page=<?php echo $prev;?>">Previous</a>
                       <?php
                    } 
                    for($i = max(1, $page - 3); $i <= min($page + 3, $total_pages); $i++) // ...print 5 links
                    {
                         ?>
                                 <a href="index.php?page=<?php echo $i;?>"><?php echo $i; ?></a>
                        <?php
                    }
                    if($page < $total_pages)
                    {
                           ?>
                                   <a href="index.php?page=<?php echo $next;?>">Next</a>
                           <?php
                    } 
                    if($result)
                    {
                        $result_user=$mysqli->use_result();
                        while($row=$result_user->fetch_array())
                        {
                                 echo '</br>'.$row['name'].'<br />';

                        }

                        $result_user->free();
                    }   
                    ?>

  ------------------------------------------------------------------------------------------------------------------------

Pagination/model/service_class.php :

<?php
    require_once 'database_connection.php';
    $con        =    new Database_connection();
    $mysqli        =    $con->new_connection();

    class Service_class
    {
            public function select_names()
        {
            global $mysqli;
            $query = "call get_statenames()";
            return $mysqli->real_query($query);
                       
        }

                 public function select_state_limit($start, $max_results)
        {
            global $mysqli;
            $query = "call get_state_limit($start, $max_results)";
            return $mysqli->real_query($query);
                       
        }     
        }
?>
 -------------------------------------------Thank you-------------------------------------------------