Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    [PHP-MySql] Problema campo ricerca

    Ciao a tutti , sono di nuovo qui a chiedervi aiuto , sono riuscita a trovare un campo ricerca ed adattarlo alle mie esigenze, se non fosse per un problema sempre con le date .

    Nella index principale la parte di codice che riguarda la ricerca e :
    Codice PHP:
        <form id="left" accept-charset="utf-8" method="get" name="searchform" width=400>
            <input type="text" value="<?php echo $searchstring?>" name="searchstring" title="<?php echo ucfmsg('SEARCH_FOR_ANY_TEXT'); ?>" style="width:200px" tabindex="0"/>
            <input type="hidden" name="company" value="<?php echo $MyCompany?>" />
            <input name="submitsearch" type="submit" value="<?php echo ucfirst(msg('SEARCH')) ?>" />    
        </form>

    <?php

    if ($searchstring) {
      
        
    $searchwords split(" "$searchstring);
      
          
    $sql " FROM $tabella ".$Ordine;
          
        foreach(
    $searchwords as $searchword) {
            
    $sql .= "AND (   data  LIKE '%$searchword%' 
                        OR nome LIKE '%
    $searchword%' 
                        OR cognome   LIKE '%
    $searchword%' 
                        OR indirizzo   LIKE '%
    $searchword%' 
                        )"
    ;
        }



        
    $sql_with_offset "SELECT DISTINCT $table.* FROM $tabella LIMIT $offset$rowsPerPage";
        
    $sql_tot "SELECT COUNT(*) as MYROWS".$sql;
        
      } else if (
    $alphabet) {
        
    $sql_with_offset "select *, date_format(data, '%d-%m-%Y') as dataformat FROM $tabella ORDER BY data DESC ".$Ordine." LIMIT $offset$rowsPerPage";
        
    $sql_tot "SELECT COUNT(*) as MYROWS FROM $tabella AND LEFT(data,1) = '$alphabet' ".$Ordine.$sql_order;
      } else{
        
    $sql_with_offset "select *, date_format(data, '%d-%m-%Y') as dataformat FROM $tabella ORDER BY data DESC ".$Ordine." LIMIT $offset$rowsPerPage";
        
    $sql_tot "SELECT COUNT(*) as MYROWS FROM $tabella ".$Ordine;
        }

        echo 
    $sql_with_offset;

        
    $result mysql_query($sql_with_offset);
        
    $numrows_tmp mysql_query($sql_tot);
        
    $numrows_tot mysql_result($numrows_tmp,0,"MYROWS");
        
    $maxPage_tot ceil($numrows_tot/$rowsPerPage);

        
    ?>
    Nella pagina mi vengono elencati i campi Data, Nome, Cognome, Indirizzo:
    -----------------------------------------
    DATA|NOME|COGNOME|INDIRIZZO
    -----------------------------------------
    03-05-2010|Maria|Rossi|Via Argine
    -----------------------------------------
    02-05-2010|Rosy |Bessa|Via Rocca
    -----------------------------------------
    e fin qui tutto ok.
    Dopo la ricerca di una parola contenuta in un campo, il risultato e la visualizzazione dei campi trovati tranne Data :
    Cerco Maria:

    -----------------------------------------
    DATA|NOME|COGNOME|INDIRIZZO
    -----------------------------------------
    __________|Maria|Rossi|Via Argine
    -----------------------------------------



    Ho provato anche a modificarlo con :

    Codice PHP:
        <form id="left" accept-charset="utf-8" method="get" name="searchform" width=400>
            <input type="text" value="<?php echo $searchstring?>" name="searchstring" title="<?php echo ucfmsg('SEARCH_FOR_ANY_TEXT'); ?>" style="width:200px" tabindex="0"/>
            <input type="hidden" name="company" value="<?php echo $MyCompany?>" />
            <input name="submitsearch" type="submit" value="<?php echo ucfirst(msg('SEARCH')) ?>" />    
        </form>

    <?php

    if ($searchstring) {
      
        
    $searchwords split(" "$searchstring);
      
          
    $sql " FROM $tabella ".$Ordine;
          
        foreach(
    $searchwords as $searchword) {
            
    $sql .= "AND (   data  LIKE '%$searchword%' 
                        OR nome LIKE '%
    $searchword%' 
                        OR cognome   LIKE '%
    $searchword%' 
                        OR indirizzo   LIKE '%
    $searchword%' 
                        )"
    ;
        }



        
    $sql_with_offset "select *, date_format(data, '%d-%m-%Y') as dataformat FROM $tabella ORDER BY data DESC ".$Ordine." LIMIT $offset$rowsPerPage";
        
    $sql_tot "SELECT COUNT(*) as MYROWS".$sql;
        
      } else if (
    $alphabet) {
        
    $sql_with_offset "select *, date_format(data, '%d-%m-%Y') as dataformat FROM $tabella ORDER BY data DESC ".$Ordine." LIMIT $offset$rowsPerPage";
        
    $sql_tot "SELECT COUNT(*) as MYROWS FROM $tabella AND LEFT(data,1) = '$alphabet' ".$Ordine.$sql_order;
      } else{
        
    $sql_with_offset "select *, date_format(data, '%d-%m-%Y') as dataformat FROM $tabella ORDER BY data DESC ".$Ordine." LIMIT $offset$rowsPerPage";
        
    $sql_tot "SELECT COUNT(*) as MYROWS FROM $tabella ".$Ordine;
        }

        echo 
    $sql_with_offset;

        
    $result mysql_query($sql_with_offset);
        
    $numrows_tmp mysql_query($sql_tot);
        
    $numrows_tot mysql_result($numrows_tmp,0,"MYROWS");
        
    $maxPage_tot ceil($numrows_tot/$rowsPerPage);

        
    ?>
    ma visualizza tutti i risultati e non il singolo contenente il termine cercato.
    Dove sbaglio? Sono sicura che il problema sia in :

    Codice PHP:
        $sql_with_offset "SELECT DISTINCT $table.* FROM $tabella LIMIT $offset$rowsPerPage"
    Grazie in anticipo a chi mi aiutera'
    Saluti
    Milena

  2. #2
    SELECT DISTINCT $table.* FROM $tabella

    $table e $tabella devono essere presenti con lo stesso valore. Il resto sinceramente non l'ho letto.

    Il silenzio è spesso la cosa migliore. Pensa ... è gratis.

  3. #3
    Ho risolto

    Il problema era proprio in :
    Codice PHP:
    $sql_with_offset "SELECT DISTINCT $table.* FROM $tabella LIMIT $offset$rowsPerPage"
    modificandolo con :
    Codice PHP:
    $sql_with_offset "SELECT *, date_format(data, '%d-%m-%Y') as dataformat".$sql." LIMIT $offset$rowsPerPage"
    ed effettuando una ricerca (es. Maria) mi visualizza:
    -----------------------------------------
    DATA|NOME|COGNOME|INDIRIZZO
    -----------------------------------------
    03-05-2010|Maria|Rossi|Via Argine
    -----------------------------------------

    Un ringraziamento a piero.mac per essere intervenuto

    Saluti
    Milena

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.