Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class crudNews
- {
- private $db;
- function __construct($DB_con)
- {
- $this->db = $DB_con;
- }
- public function create($titulo,$conteudo,$data,$img)
- {
- $data = date('d-m-Y');
- try
- {
- $stmt = $this->db->prepare("INSERT INTO tbl_noticias (titulo,conteudo,data,img) VALUES(:titulo, :conteudo, :data, :img)");
- $stmt->bindparam(":titulo",$titulo);
- $stmt->bindparam(":conteudo",$conteudo);
- $stmt->bindparam(":data",$data);
- $stmt->bindparam(":img",$img);
- $stmt->execute();
- return true;
- }
- catch(PDOException $e)
- {
- echo $e->getMessage();
- return false;
- }
- }
- public function getID($noticias_id)
- {
- $stmt = $this->db->prepare("SELECT * FROM tbl_noticias WHERE noticias_id=:noticias_id");
- $stmt->execute(array(":noticias_id"=>$noticias_id));
- $editRow=$stmt->fetch(PDO::FETCH_ASSOC);
- return $editRow;
- }
- public function update($noticias_id,$titulo,$conteudo,$data,$img)
- {
- try
- {
- $stmt=$this->db->prepare("UPDATE tbl_noticias SET titulo=:titulo,
- conteudo=:conteudo,
- data=:data,
- img=:img
- WHERE noticias_id=:noticias_id ");
- $stmt->bindparam(":titulo",$titulo);
- $stmt->bindparam(":conteudo",$conteudo);
- $stmt->bindparam(":data",$data);
- $stmt->bindparam(":img",$img);
- $stmt->bindparam(":noticias_id",$noticias_id);
- $stmt->execute();
- return true;
- }
- catch(PDOException $e)
- {
- echo $e->getMessage();
- return false;
- }
- }
- public function delete($noticias_id)
- {
- $stmt = $this->db->prepare("DELETE FROM tbl_noticias WHERE noticias_id=:noticias_id");
- $stmt->bindparam(":noticias_id",$noticias_id);
- $stmt->execute();
- return true;
- }
- /* paging */
- public function dataview($query)
- {
- $stmt = $this->db->prepare($query);
- $stmt->execute();
- if($stmt->rowCount()>0)
- {
- while($row=$stmt->fetch(PDO::FETCH_ASSOC))
- {
- ?>
- <tr>
- <td><?php print($row['noticias_id']); ?></td>
- <td><?php print($row['titulo']); ?></td>
- <td><?php print($row['conteudo']); ?></td>
- <td><?php print($row['data']); ?></td>
- <td><?php print($row['img']); ?></td>
- <td align="center">
- <a href="edit-data.php?edit_id=<?php print($row['noticias_id']); ?>"><i class="glyphicon glyphicon-edit"></i></a>
- </td>
- <td align="center">
- <a href="delete.php?delete_id=<?php print($row['noticias_id']); ?>"><i class="glyphicon glyphicon-remove-circle"></i></a>
- </td>
- </tr>
- <?php
- }
- }
- else
- {
- ?>
- <tr>
- <td>Nothing here...</td>
- </tr>
- <?php
- }
- }
- public function paging($query,$records_per_page)
- {
- $starting_position=0;
- if(isset($_GET["page_no"]))
- {
- $starting_position=($_GET["page_no"]-1)*$records_per_page;
- }
- $query2=$query." limit $starting_position,$records_per_page";
- return $query2;
- }
- public function paginglink($query,$records_per_page)
- {
- $self = $_SERVER['PHP_SELF'];
- $stmt = $this->db->prepare($query);
- $stmt->execute();
- $total_no_of_records = $stmt->rowCount();
- if($total_no_of_records > 0)
- {
- ?><ul class="pagination"><?php
- $total_no_of_pages=ceil($total_no_of_records/$records_per_page);
- $current_page=1;
- if(isset($_GET["page_no"]))
- {
- $current_page=$_GET["page_no"];
- }
- if($current_page!=1)
- {
- $previous =$current_page-1;
- echo "<li><a href='".$self."?page_no=1'>First</a></li>";
- echo "<li><a href='".$self."?page_no=".$previous."'>Previous</a></li>";
- }
- for($i=1;$i<=$total_no_of_pages;$i++)
- {
- if($i==$current_page)
- {
- echo "<li><a href='".$self."?page_no=".$i."' style='color:red;'>".$i."</a></li>";
- }
- else
- {
- echo "<li><a href='".$self."?page_no=".$i."'>".$i."</a></li>";
- }
- }
- if($current_page!=$total_no_of_pages)
- {
- $next=$current_page+1;
- echo "<li><a href='".$self."?page_no=".$next."'>Next</a></li>";
- echo "<li><a href='".$self."?page_no=".$total_no_of_pages."'>Last</a></li>";
- }
- ?></ul><?php
- }
- }
- /* paging */
- }
Advertisement
Add Comment
Please, Sign In to add comment