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

    Trovare un numero mancante...

    Ho una lista di numeri che prendo da mysql

    for ($r=1;$my = mysql_fetch_row($count);$r++)

    $my[0] saranno i vari numeri così posti: 1 2 3 4 5 6...fino ad un massimo di 10.
    Vorrei poter ricavare, se manca un numero, quel numero.

    Es.

    1 2 4

    rendermi 3.

    Se invece i numeri sono in ordine

    1 2 3 4

    rendermi 5.

    Grazie.
    GdR Online - http://lenar.it/
    Yesterday is history. Tomorrow is mystery.
    Today is a gift. That's why it's called the present

  2. #2
    cioé my[0] sarebbe una stringa del tipo "1 2 3 4 5"?

  3. #3
    $my = mysql_fetch_row($count)
    che poi metto nel ciclo or mi rende 1, 2, 3, 4ecc.
    1volta 1, poi 2, poi 3...ecc.
    Ho una tabella che rende:

    1
    ---
    2
    ---
    3
    ---
    4
    ---
    GdR Online - http://lenar.it/
    Yesterday is history. Tomorrow is mystery.
    Today is a gift. That's why it's called the present

  4. #4
    Moderatore di Server Apache L'avatar di marketto
    Registrato dal
    Sep 2001
    Messaggi
    5,858
    codice:
    $temp=array(1,2,3,4,7,8);
    $differenze=array_diff(range(1,10),$temp);
    print_r($differenze);
    think simple think ringo

  5. #5
    Faccio così:

    $my = mysql_fetch_row($count);
    $differenze=array_diff(range(1,10),$my);
    $countz=min($differenze);

    In $my ci sono dei numeri, però come faccio a trasformare i dati contenuti in $my (che ho sempre preso con un ciclo while) in un array da poter utilizzare in array_diff?
    Grazie.
    GdR Online - http://lenar.it/
    Yesterday is history. Tomorrow is mystery.
    Today is a gift. That's why it's called the present

  6. #6
    Moderatore di Server Apache L'avatar di marketto
    Registrato dal
    Sep 2001
    Messaggi
    5,858
    Originariamente inviato da Vre
    In $my ci sono dei numeri, però come faccio a trasformare i dati contenuti in $my (che ho sempre preso con un ciclo while) in un array da poter utilizzare in array_diff?
    Grazie.
    dipende da come sono memorizzati in $my: se sono separati da un particolare carattere puoi usare explode().
    think simple think ringo

  7. #7
    Un 'altra strada:

    codice:
     $buffer = " 1  2  3  4  5  6  7  8  9  10 ";
            $new='';
    
    while($row = mysql_fetch_row($res))
               {
    
                foreach($row as $value)
                        {
                        $new = " $value ";
                        $buffer = str_replace($new,'',$buffer);
                        }
               }
               echo "I numeri mancanti sono: $buffer";

  8. #8
    Grazie^__^ora le provo un po' tutte
    GdR Online - http://lenar.it/
    Yesterday is history. Tomorrow is mystery.
    Today is a gift. That's why it's called the present

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 © 2024 vBulletin Solutions, Inc. All rights reserved.