Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/12/2011, 22:49
Avatar de itemc2
itemc2
 
Fecha de Ingreso: marzo-2010
Ubicación: México
Mensajes: 8
Antigüedad: 14 años, 2 meses
Puntos: 0
Problema WHERE

Hola gente, ojalá la estén pasando bien.

Al parecer ya hay demasiados temas sobre esto, y como dicen las reglas del foro antes de hacer un tema, primero busqué si algunos otros podían ayudarme pero no encuentro una solución a esto:

Código PHP:
<?php
$tbl_name
="items";        //your table name
    // How many adjacent pages should be shown on each side?
    
$adjacents 3;
/* 
   First get total number of rows in data table. 
   If you have a WHERE clause in your query, make sure you mirror it here.
*/
    
$q=$_GET['q'];
    
/*$query = "SELECT COUNT(*) as num FROM $tbl_name";
    $total_pages = mysql_fetch_array(mysql_query($query));
    $total_pages = $total_pages[num];*/
    
    //ALTERNATIVO
    
$query mysql_query("Select * from $tbl_name WHERE item_nombre like '%$q%'");
    
$total_pages mysql_num_rows($query);
    
    if (
$total_pages '0'){
    
/* Setup vars for query. */
    
$targetpage "search.php";     //your file name  (the name of this file)
    
$limit 6;             //how many items to show per page
    
$page $_GET['page'];
    
    if(
$page
        
$start = ($page 1) * $limit;     //first item to display on this page
    
else
        
$start 0;                //if no page var is given, set start to 0
    
    /* Get data. */
    
$sql "SELECT * FROM $tbl_name WHERE item_nombre LIKE '%$q%' ORDER BY  `peliculas`.`id_item` DESC LIMIT $start, $limit";
    
//$sql = "SELECT * FROM $tbl_name WHERE item_nombre LIKE '%$q%' ORDER BY  `peliculas`.`id_item` DESC LIMIT $total_pages";
    
$result mysql_query($sql);
Ese es un fragmento de un famoso código de paginación en PHP, lo traté de adaptar para usarlo en un buscador con la variable $q y un LIKE por supuesto, pero al poner esos fragmentos la paginación simplemente no aparece.

Aquí les dejo el código original: http://phpeasystep.com/phptu/29.html

Supongo que la clave está en el comentario:

Cita:
/*
First get total number of rows in data table.
If you have a WHERE clause in your query, make sure you mirror it here.
*/
pero no logro comprenderlo, espero que me puedan ayudar.

De Antemano, Gracias