Visualizzazione dei risultati da 1 a 3 su 3

Discussione: funzione LIMIT

  1. #1
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560

    funzione LIMIT

    ciao, dovrei far visualizzare solo i primi 10 risultati del campo nel database, ho provato a inserire
    LIKE '$part%' LIMIT 10 ma non funziona, cosa sbaglio?


    Codice PHP:
    <?php

    $link 
    mysql_connect('localhost''db''passw');
    mysql_query("SET NAMES 'utf8';");
    if (!
    $link) {
       die(
    'Could not connect: ' mysql_error());
    }
    if (!
    mysql_select_db("db")) {
       echo 
    "Unable to select mydbname: " mysql_error();
       exit;
    }

    $result mysql_query("SELECT nome FROM  persone LIKE '$part%' LIMIT 10");
    while (
    $row mysql_fetch_assoc($result)) {
               
    $colors[]=$row['nome'];
    }
    mysql_free_result($result);
    mysql_close($link);

    // check the parameter
    if(isset($_GET['part']) and $_GET['part'] != '')
    {
        
    // initialize the results array
        
    $results = array();

        
    // search colors
        
    foreach($colors as $color)
        {
            
    // if it starts with 'part' add to results
            
    if( strpos($color$_GET['part']) === ){
                
    $results[] = $color;
            }
        }

        
    // return the array as json with PHP 5.2
        
    echo json_encode($results);
    }
    ?>

  2. #2
    A sembra che sia strutturata male la query...

    Codice PHP:
    SELECT nome FROM persone WHERE nome LIKE '$part%' LIMIT 10 

  3. #3
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    Grazie

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.