Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2006
    Messaggi
    121

    AIUTO impaginazione query

    Lo so, lo so è già stato detto tutto...e ci sono oramai guide e pillole super...anche sul forum
    ma nonostante ciò e con tutti gli sforzi e le prove fatte non so che fare e non mi resta che sperare in un anima gentile e paziente.
    Il problema è che devo adattarlo alla mia pagina di ricerca.....se dovessi partire da capo forse serebbe stato + facile. Ho provato 4 o 5 modalità ma non sono riuscito a farlo funz.
    Vorrei ogni 20 righe circa, creare i relativi links alle altre pagine
    il mio script è questo della pagina search.php
    Al momento ci sono nel db un 10 articoli...ma potrebbero diventare col tempo anche 100
    Se ci fosse qualche esperto che mi potesse dare una mano......in ogni caso grazie ugualmente
    Codice PHP:
    <? 
    include("config.inc.php"); 
    ?> 

    <form method=get action=search.php>
    <input type="hidden" name="cerca" value="true" /> 
    <input type=text name=chiave><input type=submit value=cerca>
     
    </form> 

    <? 
    $db 
    mysql_connect($db_host$db_user$db_password); 
    if (
    $db == FALSE
    die (
    "Errore nella connessione. Verificare i parametri nel file config.inc.php"); 
    mysql_select_db($db_name$db
    or die (
    "Errore nella selezione del database. Verificare i parametri nel file config.inc.php"); 


    if(isset (
    $_GET['cerca']) == "true"){ 
    $qs "SELECT * FROM puntivendita WHERE nome LIKE '%".mysql_escape_string($_GET['chiave'])."%' OR regione LIKE '%".mysql_escape_string($_GET['chiave'])."%' ORDER BY provincia ASC, nome ASC;";
    $qr mysql_query($qs); 
    if(
    mysql_num_rows($qr) == 0)  print("<p class=\"styletxt\">Non ci sono punti vendita al momento
    </p>"
    );
    else{ 
    while(
    $dati mysql_fetch_array($qr)){ 
    print (
    "<p class=\"styletxt\">[b]" .$dati['nome']."[/b] - ".$dati['indirizzo']." - ".$dati['citta']." - ".$dati['cap']." - [b]".$dati['provincia']."[/b] - [b]".$dati['regione']."[/b] - tel.".$dati['telefono']." - fax ".$dati['fax']." [email='".$dati[']Email[/email]</p>");  





    ?>

  2. #2
    Utente di HTML.it
    Registrato dal
    Oct 2006
    Messaggi
    121
    Ho trovato questo script ....secondo me è il più semplice......ma è da oggi che provo ad integrarlo alla mia pagina....visualizza i link alle altre pagine ma cliccando su NEXT poi la pagina è bianca e se torno indietro non ho + i risultati....ma poi mi chiedo devo dargli quanti record ho nel db? e se poi ne inserisco altri devo sempre aggiornare lo script?
    il code è questo

    Codice PHP:
    // how many rows to show per page
    $rowsPerPage 10;

    // by default we show first page
    $pageNum 1;

    // if $_GET['page'] defined, use it as page number
    if(isset($_GET['page']))
    {
        
    $pageNum $_GET['page'];
    }

    // counting the offset
    $offset = ($pageNum 1) * $rowsPerPage;

    $query  "SELECT val FROM randoms LIMIT $offset$rowsPerPage";
    $result mysql_query($query) or die('Error, query failed');

    // print the random numbers
    while(list($val) = mysql_fetch_array($result))
    {
        echo 
    "$val 
    "
    ;
    }

    echo 
    '
    '
    ;

    // how many rows we have in database
    $query   "SELECT COUNT(val) AS numrows FROM randoms";
    $result  mysql_query($query) or die('Error, query failed');
    $row     mysql_fetch_array($resultMYSQL_ASSOC);
    $numrows $row['numrows'];

    // how many pages we have when using paging?
    $maxPage ceil($numrows/$rowsPerPage);

    $self $_SERVER['PHP_SELF'];

    // creating 'previous' and 'next' link
    // plus 'first page' and 'last page' link

    // print 'previous' link only if we're not
    // on page one
    if ($pageNum 1)
    {
        
    $page $pageNum 1;
        
    $prev " <a href=\"$self?page=$page\">[Prev]</a> ";
        
        
    $first " <a href=\"$self?page=1\">[First Page]</a> ";

    else
    {
        
    $prev  ' [Prev] ';       // we're on page one, don't enable 'previous' link
        
    $first ' [First Page] '// nor 'first page' link
    }

    // print 'next' link only if we're not
    // on the last page
    if ($pageNum $maxPage)
    {
        
    $page $pageNum 1;
        
    $next " <a href=\"$self?page=$page\">[Next]</a> ";
        
        
    $last " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";

    else
    {
        
    $next ' [Next] ';      // we're on the last page, don't enable 'next' link
        
    $last ' [Last Page] '// nor 'last page' link
    }

    // print the page navigation link
    echo $first $prev " Showing page [b]$pageNum[/b] of [b]$maxPage[/b] pages " $next $last

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.