• User

    Ciao Sovietico prova cosi e dimmi cosa ti stampa:

    [php]
    //riconosco utente
    $cookie[0] = intval($cookie[0]);

    $usrinfo = $db->sql_fetchrow($db->sql_query("select * from ".$prefix."_users WHERE user_id='$cookie[0]'"));

    $userok = $usrinfo['username'];

    //controllo le liste amici
    $result = $db->sql_query("SELECT * FROM amici where richiede='$userok' AND active='1' OR amico='$userok' AND active='1' order by amico LIMIT 10");

    $amicichehai = $db->sql_numrows($db->sql_query("SELECT * FROM amici where richiede='$userok' AND active='1' OR amico='$userok' AND active='1'"));

    if($amicichehai == '0')
    {
    $final = "<center><b> Al momento non hai amici!</b></center>";
    }
    else
    {
    while ($row = $db->sql_fetchrow($result))
    {
    $amicis = $row['amico'];
    $richiede = $row['richiede'];

              //CONTROLLO I MESSAGGI NELLA SHOUT
              $resultshout = $db->sql_query("SELECT * FROM shout WHERE user = '$amicis' or user='$richiede' or global='1' order by date DESC");
              
              $totshout = $db->sql_numrows($db->sql_query("SELECT * FROM shout WHERE user = '$amici' or user='$userok' or global='1'"));
              
              if($totshout == 0) 
                {
                  $final = "<center><b>Non ci sono messaggi da parte dei tuoi amici!</b></center>";
                }
                else 
                {
                   while ($rows = $db->sql_fetchrow($resultshout)) 
                         {
    
                          $id = $rows['id'];
                          $user = $rows['user'];
                          $globale = $rows['global'];
                          $text = $rows['text'];
    
                          if($globale ==0) 
                            {
                              $final .= "<center>
                                          <table border=\"0\" width=\"80%\" cellpadding=\"2\" cellspacing=\"2\">
                                           <tr>
                                           <td width=\"1%\">$foto</td>
                                           <p><td valign=\"top\"><font color=\"#$coloreuser2\"><b>$user</a></b></font>: $text</a></p></td>
                                           <td align=\"right\">$data&nbsp;&nbsp;</td></tr>
                                          </table><hr>
                                         </center>";
                            }
                            elseif($globale != 0) 
                            {
                              $final .= "<center>
                                          <table border=\"0\" width=\"80%\" cellpadding=\"2\" cellspacing=\"2\"><tr>
                                           <td width=\"1%\"><img src=\"images/danger/warning.gif\" title=\"Attenzione: Messaggio Globale\" align=\"left\"></td>
                                           <td valign=\"top\"><font color=\"red\"><b>Messaggio Globale</a></b></font>: $text</a></td>
                                           <td align=\"right\"><img src=\"images/alert.gif\" title=\"Messaggio Globale $id\"></td></tr>
                                          </table><hr>
                                         </center>";
                            }
                            
                          }//while
                 }//else
                 
           }//while
    

    }//else

    echo "$final<br><br>";
    [/php]


  • User Attivo

    Ciao giovandres90,

    stessa e identica cosa di prima 😞

    Praticamente vengono stampati i mex del primo amico + quelli in prima persona, poi vengono stampati i mex del secondo amico + quelli in prima persona e così via..

    Bisognerebbe eliminare il While del controllo amici, ma non sò che soluzione adottare.

    Grazie infinite per l'interessamento!


  • ModSenior

    Devi fare una cosa ti questo tipo:
    [php]
    <?php
    //riconosco utente
    $cookie[0] = intval($cookie[0]);
    $usrinfo = $db->sql_fetchrow($db->sql_query("select * from ".$prefix."_users WHERE user_id='$cookie[0]'"));
    $userok = $usrinfo['username'];
    //controllo le liste amici
    $result = $db->sql_query("SELECT * FROM amici where richiede='$userok' AND active='1' OR amico='$userok' AND active='1' order by amico");
    $amicichehai = $db->sql_numrows($db->sql_query("SELECT * FROM amici where richiede='$userok' AND active='1' OR amico='$userok' AND active='1'"));
    if($amicichehai == '0') {
    $final = "<center><b> Al momento non hai amici!</b></center>";
    }
    else {
    $where = '';
    while ($row = $db->sql_fetchrow($result)) {
    $amicis = $row['amico'];
    $richiede = $row['richiede'];
    if($amicis == $userok) { $amici = $richiede; }
    else if($amicis != $userok) { $amici = $amicis; }

    $where.= ' OR user = '.$amici;
    }
    
     //CONTROLLO I MESSAGGI NELLA SHOUT
    $resultshout = $db->sql_query("SELECT * FROM shout WHERE user='$userok' or global=1 $where order by date DESC");
    $totshout = $db->sql_numrows($resultshout);
    if($totshout == 0) {$final = "<center><b>Non ci sono messaggi da parte dei tuoi amici!</b></center>";}
    else {
    while ($rows = $db->sql_fetchrow($resultshout)) {
    
    $id = $rows['id'];
    $user = $rows['user'];
    $globale = $rows['global'];
    $text = $rows['text'];
    

    if($globale ==0) {
    $final .= "<center><table border="0" width="80%" cellpadding="2" cellspacing="2"><tr><td width="1%">$foto</td><p><td valign="top"><font color="#$coloreuser2"><b>$user</a></b></font>: $text</a></p></td><td align="right">$data  </td></tr></table><hr></center>";
    }
    if($globale != 0) {
    $final .= "<center><table border="0" width="80%" cellpadding="2" cellspacing="2"><tr><td width="1%"><img src="images/danger/warning.gif" title="Attenzione: Messaggio Globale" align="left"></td><td valign="top"><font color="red"><b>Messaggio Globale</a></b></font>: $text</a></td><td align="right"><img src="images/alert.gif" title="Messaggio Globale $id"></td></tr></table><hr></center>";
    }
    }

    }
    }

    echo "$final<br><br>";
    [/php]


  • User Attivo

    Ciao Thedarkita,

    Non trova risultati.

    stampa: Non ci sono messaggi da parte dei tuoi amici!


  • ModSenior

    Sotto:
    [php]
    $resultshout = $db->sql_query("SELECT * FROM shout WHERE user='$userok' or global=1 $where order by date DESC");
    [/php]
    Metti:
    [php]
    echo "SELECT * FROM shout WHERE user='$userok' or global=1 $where order by date DESC";
    [/php]
    E incolla qui la query che ti mostra.


  • User Attivo

    Forse perchè mancano gli apici?

    
    SELECT * FROM shout WHERE user='Dangerous' or global=1 OR user = Test OR user = Prova order by date DESC
    
    Non ci sono messaggi da parte dei tuoi amici!
    
    

  • ModSenior

    Ah ecco, tu conservi i nick e non gli id, per cui:
    [php]
    <?php
    //riconosco utente
    $cookie[0] = intval($cookie[0]);
    $usrinfo = $db->sql_fetchrow($db->sql_query("select * from ".$prefix."_users WHERE user_id='$cookie[0]'"));
    $userok = $usrinfo['username'];
    //controllo le liste amici
    $result = $db->sql_query("SELECT * FROM amici where richiede='$userok' AND active='1' OR amico='$userok' AND active='1' order by amico");
    $amicichehai = $db->sql_numrows($db->sql_query("SELECT * FROM amici where richiede='$userok' AND active='1' OR amico='$userok' AND active='1'"));
    if($amicichehai == '0') {
    $final = "<center><b> Al momento non hai amici!</b></center>";
    }
    else {
    $where = '';
    while ($row = $db->sql_fetchrow($result)) {
    $amicis = $row['amico'];
    $richiede = $row['richiede'];
    if($amicis == $userok) { $amici = $richiede; }
    else if($amicis != $userok) { $amici = $amicis; }

    $where.= ' OR user = \''.$amici.'\'';
    }
    
     //CONTROLLO I MESSAGGI NELLA SHOUT
    $resultshout = $db->sql_query("SELECT * FROM shout WHERE user='$userok' or global=1 $where order by date DESC");
    $totshout = $db->sql_numrows($resultshout);
    if($totshout == 0) {$final = "<center><b>Non ci sono messaggi da parte dei tuoi amici!</b></center>";}
    else {
    while ($rows = $db->sql_fetchrow($resultshout)) {
    
    $id = $rows['id'];
    $user = $rows['user'];
    $globale = $rows['global'];
    $text = $rows['text'];
    

    if($globale ==0) {
    $final .= "<center><table border="0" width="80%" cellpadding="2" cellspacing="2"><tr><td width="1%">$foto</td><p><td valign="top"><font color="#$coloreuser2"><b>$user</a></b></font>: $text</a></p></td><td align="right">$data  </td></tr></table><hr></center>";
    }
    if($globale != 0) {
    $final .= "<center><table border="0" width="80%" cellpadding="2" cellspacing="2"><tr><td width="1%"><img src="images/danger/warning.gif" title="Attenzione: Messaggio Globale" align="left"></td><td valign="top"><font color="red"><b>Messaggio Globale</a></b></font>: $text</a></td><td align="right"><img src="images/alert.gif" title="Messaggio Globale $id"></td></tr></table><hr></center>";
    }
    }

    }
    }

    echo "$final<br><br>"; [/php]


  • User Attivo

    Cosa dire.. Grazie mille a tutti, sembra funzionare regolarmente! 🙂


  • User

    Ma in teoria tu cosa vuoi stampare? dici come hai strutturato la tabella del db? se non avevo capito male tu volevi stampare tutti i messagi dei amici del user + i suoi giusto ?


  • User Attivo

    @giovandres90 said:

    Ma in teoria tu cosa vuoi stampare? dici come hai strutturato la tabella del db? se non avevo capito male tu volevi stampare tutti i messagi dei amici del user + i suoi giusto ?

    Esatto.

    Ho la tabella amici

    Amico - Richiede - Data

    E la tabella shout

    user - text - data - global

    Lo script modificato da Thedarkita funziona perfettamente, anche se mi vengono dubbi sulla pesantezza.. Cosa succede se ci sono 400 amici e oltre 10k di messaggi? lol

    Ora devo implementare il marquee per lo scroll e mettere un limite max di messaggi, oltre che eliminare in automatico i messaggi vecchi di 1 settimana.

    Ciao!


  • ModSenior

    Con l'aumentare della grandezza della tabella è ababstanza ovvio che i tempi di elaborazioni diventano più lunghi, volendo invece di fare 2 query sarebbe anche possibile ridurre il tutto ad 1 sola cosa che in certi casi mi sembrerebbe più performante, se il numero di messaggi scritti è abbastanza basso e quindi magari per qualche ora hai sempre gli stessi messaggi da mostrare, puoi anche implementare una cache.


  • User Attivo

    Sì Thedarkita, hai perfettamente ragione, ma credo che per iniziare è più che sufficiente, tutto dipenderà dalla mole di utenza.

    Se un domani l'utenza e i messaggi saranno tantissimi, si provvederà alla modifica.

    Per il momento sono più che soddisfatto di come funziona. 🙂