• User Newbie

    Snellire il codice per renderlo più funzionale

    Ciao a tutti

    Volevo sapere se qualcuno sa scrivere in maniera più intelligente questo codice.
    Nel database ogni utente ha disposizione la registrazione di 5 set di informazioni, ogni set ha 3 caratteristiche: larghezza (lar), lunghezza (lun) e colore (col).
    Quando tutte e tre le caratteristiche dello stesso set combaciano con un set di un altro utente c'è la possibilità di metterli in contatto.

    Qui sotto posto il codice che ho scritto, che per funzionare funziona, ma non c'è un modo più semplice per fa ciò, in modo anche di non sovraccaricare il server ?

    Ogni utente nel database ha i campi lar1 lun1 col1 (primo set), lar2 lun2 col2 (secondo set) e cosi via fino a al 5

    Spero in voi !

    Ciao !

    //Verifico se ci sono dati uguali nel primo set;
    $sql = "SELECT nick, email FROM utenti where nick<>'$nome_utente' and lar1='$lar1' and lun1='$lun1' and col1='$col1' or nick<>'$nome_utente' and lar2='$lar1' and lun2='$lun1' and col2='$col1' or nick<>'$nome_utente' and lar3='$lar1' and lun3='$lun1' and col3='$col1' or nick<>'$nome_utente' and lar4='$lar1' and lun4='$lun1' and col4='$col1' or nick<>'$nome_utente' and lar5='$lar1' and lun5='$lun1' and col5='$col1'";

    $row = mysqli_fetch_assoc($result);

    $result = mysqli_query($cxn,$sql);

    while($row = mysqli_fetch_row($result))
    {
    $nick01="$row[0]";
    $email01="$row[1]";
    }
    // segno ok se la verifica ha esito positivo e preparo dati per spedizione messaggio

    if($nick01>"0"){
    

    $check1="ok" ;
    }
    else
    {
    $check1="ko";}

    //Verifico se ci sono dati uguali nel secondo set;
    $sql = "SELECT nick, email FROM utenti where nick<>'$nome_utente' and lar1='$lar2' and lun1='$lun2' and col1='$col2' or nick<>'$nome_utente' and lar2='$lar2' and lun2='$lun2' and col2='$col2' or nick<>'$nome_utente' and lar3='$lar2' and lun3='$lun2' and col3='$col2' or nick<>'$nome_utente' and lar4='$lar2' and lun4='$lun2' and col4='$col2' or nick<>'$nome_utente' and lar5='$lar2' and lun5='$lun2' and col5='$col2'";

    $row = mysqli_fetch_assoc($result);

    $result = mysqli_query($cxn,$sql);

    while($row = mysqli_fetch_row($result))
    {
    $nick02="$row[0]";
    $email02="$row[1]";
    }
    // segno ok se la verifica ha esito positivo e preparo dati per spedizione messaggio

    if($nick01>"0"){
    

    $check2="ok" ;
    }
    else
    {
    $check2="ko";}

    //Verifico se ci sono dati uguali nel terzo set;
    $sql = "SELECT nick, email FROM utenti where nick<>'$nome_utente' and lar1='$lar3' and lun1='$lun3' and col1='$col3' or nick<>'$nome_utente' and lar2='$lar3' and lun2='$lun3' and col2='$col3' or nick<>'$nome_utente' and lar3='$lar3' and lun3='$lun3' and col3='$col3' or nick<>'$nome_utente' and lar4='$lar3' and lun4='$lun3' and col4='$col3' or nick<>'$nome_utente' and lar5='$lar3' and lun5='$lun3' and col5='$col3'";

    $row = mysqli_fetch_assoc($result);

    $result = mysqli_query($cxn,$sql);

    while($row = mysqli_fetch_row($result))
    {
    $nick03="$row[0]";
    $email03="$row[1]";
    }
    // segno ok se la verifica ha esito positivo e preparo dati per spedizione messaggio

    if($nick01>"0"){
    

    $check3="ok" ;
    }
    else
    {
    $check3="ko";}

    //Verifico se ci sono dati uguali nel quarto set;
    $sql = "SELECT nick, email FROM utenti where nick<>'$nome_utente' and lar1='$lar4' and lun1='$lun4' and col1='$col4' or nick<>'$nome_utente' and lar2='$lar4' and lun2='$lun4' and col2='$col4' or nick<>'$nome_utente' and lar3='$lar4' and lun3='$lun4' and col3='$col4' or nick<>'$nome_utente' and lar4='$lar4' and lun4='$lun4' and col4='$col4' or nick<>'$nome_utente' and lar5='$lar4' and lun5='$lun4' and col5='$col4'";

    $row = mysqli_fetch_assoc($result);

    $result = mysqli_query($cxn,$sql);

    while($row = mysqli_fetch_row($result))
    {
    $nick04="$row[0]";
    $email04="$row[1]";
    }
    // segno ok se la verifica ha esito positivo e preparo dati per spedizione messaggio

    if($nick01>"0"){
    

    $check4="ok" ;
    }
    else
    {
    $check4="ko";}

    //Verifico se ci sono dati uguali nel quinto set;
    $sql = "SELECT nick, email FROM utenti where nick<>'$nome_utente' and lar1='$lar5' and lun1='$lun5' and col1='$col5' or nick<>'$nome_utente' and lar2='$lar5' and lun2='$lun5' and col2='$col5' or nick<>'$nome_utente' and lar3='$lar5' and lun3='$lun5' and col3='$col5' or nick<>'$nome_utente' and lar4='$lar5' and lun4='$lun5' and col4='$col5' or nick<>'$nome_utente' and lar5='$lar5' and lun5='$lun5' and col5='$col5'";

    $row = mysqli_fetch_assoc($result);

    $result = mysqli_query($cxn,$sql);

    while($row = mysqli_fetch_row($result))
    {
    $nick05="$row[0]";
    $email05="$row[1]";
    }
    // segno ok se la verifica ha esito positivo e preparo dati per spedizione messaggio

    if($nick01>"0"){
    

    $check5="ok" ;
    }
    else
    {
    $check5="ko";}