Created
May 23, 2018 23:50
-
-
Save MarcAnt/1aae3994a94c7212c1cdf6dc2398d908 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| try { | |
| $conexion = new PDO("mysql:host=localhost;dbname=laferia", "root", ""); | |
| }catch(PDOException $e) { | |
| echo "ERROR" , $e->getMessage(); | |
| die(); | |
| } | |
| $pagina = isset($_GET['pagina']) ? (int)$_GET['pagina'] : 1; | |
| $porPagina = 3; | |
| $inicio = ($pagina > 1) ? ($pagina *$porPagina - $porPagina): 0; | |
| if($_SERVER['REQUEST_METHOD' ] == 'GET' && !empty($_GET['busqueda'])) { | |
| $busqueda = $_GET['busqueda']; | |
| $statement = $conexion->prepare("SELECT SQL_CALC_FOUND_ROWS * FROM productos WHERE nombre LIKE :busqueda | |
| OR tipo LIKE :busqueda | |
| LIMIT $inicio,$porPagina"); | |
| $statement->execute(array(":busqueda"=> "%$busqueda%")); | |
| $consulta = $statement->fetchAll(); | |
| $totalProductos = $conexion->query("SELECT FOUND_ROWS() as total"); | |
| $totalProductos = $totalProductos->fetch()['total']; | |
| //echo "Total de productos: ", $totalProductos, "<br>"; | |
| $totalPaginas = ceil($totalProductos/$porPagina); | |
| //echo "Total de paginas por productos: ", $totalPaginas , "<br>"; | |
| }else { | |
| //header('Location: index.php?pagina=1'); | |
| header('Location: ampolla'); | |
| } | |
| require "buscar.view.php"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment