Sconosciuti e Conosciuti
Sconosciuti e Conosciuti postato il 25/06/2008 10:44:25 nel forum programmazione, open source e hosting e modificato da darck il 25/06/2008 10:45:26
Salve ragazzi,
rieccomi con tutti i miei problemi 😎
Allora, io vorrei fare che, se il personaggio Tizio non conosce il personaggio Caio in ON, Tizio nella chat non visualizza il nome di Caio ma bensì solamente "Sconosciuto/a". Per farlo, ho creato il parametro "Amicizie" nel database e ho provato a fare un principio di code che pensavo fosse corretto:
<?
$conn = mysql_connect('localhost', 'user', 'pass');
mysql_select_db('my_deathnotepbc');
$cur = mysql_query ("
SELECT *
FROM Personaggio
WHERE Nome = '$Login'
");
$Result = mysql_query($MySql);
$rs = mysql_fetch_array($Result);
if ($rs['Amicizie'] == $rs['Mittente']) {
case 'P': #Messaggio Pubblico
$testo = $rs['Testo'];
$testo = str_replace('[', '[<font color=gray>', $testo);
$testo = str_replace(']', '</font>]', $testo);
$testo = str_replace('«', '«<font color=red>', $testo);
$testo = str_replace('»', '</font>»', $testo);
$n = '<FONT CLASS=Testo><FONT CLASS=Micro>'.Tempo($rs['Ora']).'</FONT> <IMG SRC='img/testamini'.strtolower($rs['Sesso']).'.gif' width=8 height=8 border=0 Alt="Messaggio privato" onclick="Javascript:parent.chatinput.document.invio.Messaggio.value='@'.$rs['Mittente'].'@';parent.chatinput.document.invio.Messaggio.focus()"> <B>'.htmlspecialchars($rs['Mittente']).'</B> <A href='scheda.php?pg='.urlencode($rs['Mittente']).'' target=palestra Title="'.pars($rs['DescGilda']).' - '.pars($rs['DescRazza']).'"><IMG SRC='img/stemmi/'.$rs['ImgGilda']."' border=0 align=bottom title="".pars($rs['DescGilda'])." - ".pars($rs['DescRazza']).'"></A> '.$testo.'</FONT><BR>';
break;
}
else
{
case 'P': #Messaggio Pubblico
$testo = $rs['Testo'];
$testo = str_replace('[', '[<font color=gray>', $testo);
$testo = str_replace(']', '</font>]', $testo);
$testo = str_replace('«', '«<font color=red>', $testo);
$testo = str_replace('»', '</font>»', $testo);
$n = '<FONT CLASS=Testo><FONT CLASS=Micro>'.Tempo($rs['Ora']).'</FONT> <IMG SRC='img/testamini'.strtolower($rs['Sesso']).'.gif' width=8 height=8 border=0 Alt="Messaggio privato" onclick="Javascript:parent.chatinput.document.invio.Messaggio.value='@'.$rs['Mittente'].'@';parent.chatinput.document.invio.Messaggio.focus()"> <B>Sconosciuto/a</B> <A href='scheda.php?pg='.urlencode($rs['Mittente']).'' target=palestra Title="'.pars($rs['DescGilda']).' - '.pars($rs['DescRazza']).'"><IMG SRC='img/stemmi/'.$rs['ImgGilda']."' border=0 align=bottom title="".pars($rs['DescGilda'])." - ".pars($rs['DescRazza']).'"></A> '.$testo.'</FONT><BR>';
break;
}
mysql_close($conn);
?>
In pratica, se il PG Caio è presente nel parametro amicizie del PG Tizio, esso lo visualizza con il nome, altrimenti, visualizza "Sconosciuto/a". Potete aiutarmi?
Pagine → 1
25/06/2008 11:11:07
Se vuoi fare così devi imporre che il campo amicizie è un insieme diciamo ordinato, con i vari nomi separati da un identificatore che vuoi tu. Poi puoi fare in due modi: o esplodi la stringa rendendola un array e poi compari Amicizie con il nome del mittente oppure puoi usare una funzione predefinita per il trattamento delle stringhe che trova nell'elenco di Amicizie il nome del mittente e vedi che se da un valore vero lo fa come conosciuto e stampa il nome sennò fa sconosciuto.
25/06/2008 11:14:19
toth ha scritto: Se vuoi fare così devi imporre che il campo amicizie è un insieme diciamo ordinato, con i vari nomi separati da un identificatore che vuoi tu. Poi puoi fare in due modi: o esplodi la stringa rendendola un array e poi compari Amicizie con il nome del mittente oppure puoi usare una funzione predefinita per il trattamento delle stringhe che trova nell'elenco di Amicizie il nome del mittente e vedi che se da un valore vero lo fa come conosciuto e stampa il nome sennò fa sconosciuto.
Sicuramente uso il secondo metodo. Potresti farmi un esempio veloce?
25/06/2008 11:30:35
Primo modo:
<?
$conn = mysql_connect('localhost', 'user', 'pass');
mysql_select_db('my_deathnotepbc');
$cur = mysql_query ("
SELECT *
FROM Personaggio
WHERE Nome = '$Login'
");
$Result = mysql_query($MySql);
$rs = mysql_fetch_array($Result);
$Amici=$rs['Amicizie'];
$amiciziearray = explode('@',$Amici);
if ($amiciziearray == $rs['Mittente']) {
case 'P': #Messaggio Pubblico
$testo = $rs['Testo'];
$testo = str_replace('[', '[<font color=gray>', $testo);
$testo = str_replace(']', '</font>]', $testo);
$testo = str_replace('«', '«<font color=red>', $testo);
$testo = str_replace('»', '</font>»', $testo);
$n = '<FONT CLASS=Testo><FONT CLASS=Micro>'.Tempo($rs['Ora']).'</FONT> <IMG SRC='img/testamini'.strtolower($rs['Sesso']).'.gif' width=8 height=8 border=0 Alt="Messaggio privato" onclick="Javascript:parent.chatinput.document.invio.Messaggio.value='@'.$rs['Mittente'].'@';parent.chatinput.document.invio.Messaggio.focus()"> <B>'.htmlspecialchars($rs['Mittente']).'</B> <A href='scheda.php?pg='.urlencode($rs['Mittente']).'' target=palestra Title="'.pars($rs['DescGilda']).' - '.pars($rs['DescRazza']).'"><IMG SRC='img/stemmi/'.$rs['ImgGilda']."' border=0 align=bottom title="".pars($rs['DescGilda'])." - ".pars($rs['DescRazza']).'"></A> '.$testo.'</FONT><BR>';
break;
}
else
{
case 'P': #Messaggio Pubblico
$testo = $rs['Testo'];
$testo = str_replace('[', '[<font color=gray>', $testo);
$testo = str_replace(']', '</font>]', $testo);
$testo = str_replace('«', '«<font color=red>', $testo);
$testo = str_replace('»', '</font>»', $testo);
$n = '<FONT CLASS=Testo><FONT CLASS=Micro>'.Tempo($rs['Ora']).'</FONT> <IMG SRC='img/testamini'.strtolower($rs['Sesso']).'.gif' width=8 height=8 border=0 Alt="Messaggio privato" onclick="Javascript:parent.chatinput.document.invio.Messaggio.value='@'.$rs['Mittente'].'@';parent.chatinput.document.invio.Messaggio.focus()"> <B>Sconosciuto/a</B> <A href='scheda.php?pg='.urlencode($rs['Mittente']).'' target=palestra Title="'.pars($rs['DescGilda']).' - '.pars($rs['DescRazza']).'"><IMG SRC='img/stemmi/'.$rs['ImgGilda']."' border=0 align=bottom title="".pars($rs['DescGilda'])." - ".pars($rs['DescRazza']).'"></A> '.$testo.'</FONT><BR>';
break;
}
mysql_close($conn);
?>
$amiciziearray = explode('@',$Amici); tramite questo codice tu crei un array (appunto amiciziearray) che ha come valori tutti i nomi degli amici.
Il campo Amicizie nel database deve essere obbligatoriamente nella forma:
Amico1@Amico2@Amico3@Amico4
e così via.
Secondo Modo:
<?
$conn = mysql_connect('localhost', 'user', 'pass');
mysql_select_db('my_deathnotepbc');
$cur = mysql_query ("
SELECT *
FROM Personaggio
WHERE Nome = '$Login'
");
$Result = mysql_query($MySql);
$rs = mysql_fetch_array($Result);
if (strrpos($rs['Amicizie'],$rs['Mittente'])===true) {
case 'P': #Messaggio Pubblico
$testo = $rs['Testo'];
$testo = str_replace('[', '[<font color=gray>', $testo);
$testo = str_replace(']', '</font>]', $testo);
$testo = str_replace('«', '«<font color=red>', $testo);
$testo = str_replace('»', '</font>»', $testo);
$n = '<FONT CLASS=Testo><FONT CLASS=Micro>'.Tempo($rs['Ora']).'</FONT> <IMG SRC='img/testamini'.strtolower($rs['Sesso']).'.gif' width=8 height=8 border=0 Alt="Messaggio privato" onclick="Javascript:parent.chatinput.document.invio.Messaggio.value='@'.$rs['Mittente'].'@';parent.chatinput.document.invio.Messaggio.focus()"> <B>'.htmlspecialchars($rs['Mittente']).'</B> <A href='scheda.php?pg='.urlencode($rs['Mittente']).'' target=palestra Title="'.pars($rs['DescGilda']).' - '.pars($rs['DescRazza']).'"><IMG SRC='img/stemmi/'.$rs['ImgGilda']."' border=0 align=bottom title="".pars($rs['DescGilda'])." - ".pars($rs['DescRazza']).'"></A> '.$testo.'</FONT><BR>';
break;
}
else
{
case 'P': #Messaggio Pubblico
$testo = $rs['Testo'];
$testo = str_replace('[', '[<font color=gray>', $testo);
$testo = str_replace(']', '</font>]', $testo);
$testo = str_replace('«', '«<font color=red>', $testo);
$testo = str_replace('»', '</font>»', $testo);
$n = '<FONT CLASS=Testo><FONT CLASS=Micro>'.Tempo($rs['Ora']).'</FONT> <IMG SRC='img/testamini'.strtolower($rs['Sesso']).'.gif' width=8 height=8 border=0 Alt="Messaggio privato" onclick="Javascript:parent.chatinput.document.invio.Messaggio.value='@'.$rs['Mittente'].'@';parent.chatinput.document.invio.Messaggio.focus()"> <B>Sconosciuto/a</B> <A href='scheda.php?pg='.urlencode($rs['Mittente']).'' target=palestra Title="'.pars($rs['DescGilda']).' - '.pars($rs['DescRazza']).'"><IMG SRC='img/stemmi/'.$rs['ImgGilda']."' border=0 align=bottom title="".pars($rs['DescGilda'])." - ".pars($rs['DescRazza']).'"></A> '.$testo.'</FONT><BR>';
break;
}
mysql_close($conn);
?>
if (strpos($rs['Amicizie'],$rs['Mittente'])===true) in questo secondo metodo usi la variabile strpos che se non erro da true se trova la seconda stringa nella prima se non la trova da false. Anche in questo caso il campo amicizie ti consiglio di farlo ordinato, in modo da diminuire la percentuale di errori.
Attenzione... non garantisco del funzionamento del codice :P può ese buggato, tocca a voi vedè ^^
25/06/2008 11:36:35
Quando scrivo non visualizza quello che scrivo, cosa che fa sempre quando c'è un bug. Sto cercando di trovare l'errore.. 😵
25/06/2008 13:04:19
Allora, abbiamo aggiustato un pò di cose ed ora non dà più errore. Però non funziona lo stesso, mi dà sempre sconosciuto anche quando dovrebbe riconoscermi il nome:
case 'P': #Messaggio Pubblico
$testo = $rs['Testo'];
$testo = str_replace('[', '[<font color=gray>', $testo);
$testo = str_replace(']', '</font>]', $testo);
$testo = str_replace('«', '«<font color=red>', $testo);
$testo = str_replace('»', '</font>»', $testo);
$cur = mysql_query ("SELECT * FROM Personaggio WHERE Nome = '$Login'");
$rs2 = mysql_fetch_array($cur);
echo $rs2['Amicizie'];
$Amici=$rs2['Amicizie'];
echo $Amici;
$amiciziearray = explode('!',$Amici);
echo $amiciziearray[0].$amiciziearray[1];
if ($amiciziearray == $rs['Mittente']) {
$n = "<FONT CLASS=Testo><FONT CLASS=Micro>".Tempo($rs['Ora'])."</FONT> <IMG SRC='img/testamini".strtolower($rs['Sesso']).".gif' width=8 height=8 border=0 Alt='Messaggio privato' onclick='Javascript:parent.chatinput.document.invio.Messaggio.value='@".$rs['Mittente']."@';parent.chatinput.document.invio.Messaggio.focus()'> <B>".htmlspecialchars($rs['Mittente'])."</B> <A href='scheda.php?pg=".urlencode($rs['Mittente'])."' target=palestra Title='".pars($rs['DescGilda'])." - ".pars($rs['DescRazza'])."'><IMG SRC='img/stemmi/".$rs['ImgGilda']."' border=0 align=bottom title='".pars($rs['DescGilda'])." - ".pars($rs['DescRazza'])."'></A> ".$testo."</FONT><BR>";
}
else
{
$n = "<FONT CLASS=Testo><FONT CLASS=Micro>".Tempo($rs['Ora'])."</FONT> <IMG SRC='img/testamini".strtolower($rs['Sesso']).".gif' width=8 height=8 border=0 Alt='Messaggio privato' onclick='Javascript:parent.chatinput.document.invio.Messaggio.value='@".$rs['Mittente']."@';parent.chatinput.document.invio.Messaggio.focus()'> <B>Sconosciuto/a</B> <A href='scheda.php?pg=".urlencode($rs['Mittente'])."' target=palestra Title='".pars($rs['DescGilda'])." - ".pars($rs['DescRazza'])."'><IMG SRC='img/stemmi/".$rs['ImgGilda']."' border=0 align=bottom title='".pars($rs['DescGilda'])." - ".pars($rs['DescRazza'])."'></A> ".$testo."</FONT><BR>";
}
break;
}
Qualcuno sà perchè? Nel campo amicizie ho scritto !NomePg ma non lo riconosce. Ho tentato anche con !NomePg! ma niente. Sapete aiutarmi?
Discussione seguita da
Pagine → 1
Rispondi alla Discussione Segui Discussione Inoltra Discussione Forum Programmazione, Open Source e Hosting Elenco Forum
Articoli, Interviste e altre Risorse!
New Orleans ↗
RAID Shadow Legends ↗
War Thunder ↗
World of the Sea Battle ↗
Tibia ↗