Problema visualizzazione lista amici

sappe

Nuovo Utente
27 Mar 2011
27
0
0
In una pagina che dovrebbe stamparmi la lista degli utenti amici dell'utente collegato ho scritto questo codice php:
Codice:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?php session_start(); 
$IDutente = $_SESSION['IDutente'];?>
<HTML>
<HEAD>
<TITLE>Your Friends</TITLE><link href="style.css" rel="stylesheet" type="text/css">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
</HEAD>
<BODY>
<div align="center">
  <TABLE class="maintable" CELLPADDING="0" CELLSPACING="0">
    <TR> 
      <TD COLSPAN=3> <IMG SRC="images/index_01.gif" WIDTH=727 HEIGHT=240 ALT=""></TD>
    </TR>
    <TR> 
      <TD ROWSPAN=2 class="navbg" valign="top"><div id="nav">
          <p><span class="h2">Menu</span> <a href="index.php">Home</a> <a href="rules.php">Rules</a> 
            <a href="gallery.php">Gallery</a> <a href="upload.php">Upload</a> <a href="search.php">Search</a>
            <span class="endbox"></span> </p>
						
         
					
<?php 
if ((isset($_SESSION['login']))&&((isset($_SESSION['password'])))){
   echo <<<print
	 
	 <p><span class="h2">Logout</span> <a href="profile.php">Your Profile</a> <a href="logout.php">Logout</a><span class="endbox"></span> </p>
         <p><span class="h2">Friendship</span> <a href="users.php">Search user</a> <a href="friend.php">My friends</a> <a href="request.php">Friends request</a> <span class="endbox"></span> </p>
print;
}
else {
   echo <<<print
	 
	 <p><span class="h2">Sign in</span> <a href="create.html">Create account</a> <a href="login.htm">Login</a><span class="endbox"></span>
print;
}
echo <<<print

 </p>
        </div></TD>
      <TD ROWSPAN=2 class="contentbg" valign="top"><div id="content">
          
print;

 ?>
          <h1>Friend page:</h1>
<h2 align="center">Your friends:</h2>
<?php 
include ("connessione.inc");
$sql="SELECT nickname FROM utenti WHERE IDutente = ALL (SELECT Receiver AS amico FROM amicizie WHERE (Sender = '$IDutente') AND (Friend = '1') UNION SELECT Sender AS amico FROM amicizie WHERE (Receiver = '$IDutente') AND (Friend = '1'))";
$res = mysql_query($sql, $conn) or die("Error!".mysql_error());
while ($records = mysql_fetch_assoc($res)){
   echo <<<MESS
<a href=\"?page="profile.php?id=$records[nickname]\" title=\"Go to his profile\" id=\"previus\">$records[nickname]</a>
<form action="friend.php" id="delete" method="POST" align="right">
<input type="submit" name="button" value="Delete" class="button"/> 
</form>
MESS;
}
//codice del bottone Delete
if (isset($_POST['button'])){
$button=$_POST['button'];
   if ($button == "Delete"){
       $sql2="DELETE FROM amicizie WHERE (Receiver = '$IDutente' and Sender = '$records[nickname]') or (Sender = '$records[nickname]' and Receiver = '$IDutente')";
	     $res2=mysql_query($sql2, $conn) or die("Error!".mysql_error()); 
	 echo "You and $records[nickname] aren't longer friend.";
	 }
}
?>	
 </p>

				</p>

          </br>
					</br>
					</br>
					</br>
          <h1>©SketchMania</h1>
			<TD valign="top" class="spacer"></TD>
    </TR><TR> 
      <TD height="2" class="spacer2"></TD>
    </TR><TR> 
      <TD COLSPAN=3 class="creditsbg">
				<p>| Contact us <a href="http://yahoo.com/" target="_blank">sketchmania@yahoo.com</a> | </p></TD>
    </TR>
  </TABLE>
</div>
</BODY>
</HTML>
Ovviamente l'errore è nella richiesta sql, che riscrivo qua:
Codice:
SELECT nickname FROM utenti WHERE IDutente = ALL (SELECT Receiver AS amico FROM amicizie WHERE (Sender = '$IDutente') AND (Friend = '1') UNION SELECT Sender AS amico FROM amicizie WHERE (Receiver = '$IDutente') AND (Friend = '1'))
Il mio database è questo:
http://www.mediafire.com/?j0b4sujt2twja3t
Sono stata ingannata dal fatto che ieri funzionava, ma avevo solo una amicizia con lo stato '1', quindi solo una accettata. Adesso, però, non riesco assolutamente più a richiamare tramite sql l'altro utente (prima di scrivere ho provato sul database ma nisba).
Avete qualche idea di come potrei effettuare la query?
Spero vivamente di non aver sbagliato sezione, vi ringrazio in anticipo per l'aiuto e la pazienza :).
 
ciao
per prima cosa inverti le due righe
PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?php session_start(); 
$IDutente = $_SESSION['IDutente'];?>
in questo modo

PHP:
<?php session_start(); 
$IDutente = $_SESSION['IDutente'];?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
session_start deve essere la prima istruzione prima dei tag html (output html)
poi i resto ci do un occhio
 
ciao
per prima cosa inverti le due righe
PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?php session_start(); 
$IDutente = $_SESSION['IDutente'];?>
in questo modo

PHP:
<?php session_start(); 
$IDutente = $_SESSION['IDutente'];?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
session_start deve essere la prima istruzione prima dei tag html (output html)
poi i resto ci do un occhio
Grazie della dritta :D se tu mi sapessi aiutare non so dirti quanto te ne sarei grata!
 
ciao
scusa ma non capisco bene (premetto che non sono molto esperto di mysql).
PHP:
<?php
//....
$sql="SELECT nickname FROM utenti 
WHERE IDutente = ALL (SELECT Receiver AS amico FROM amicizie WHERE (Sender = '$IDutente') AND (Friend = '1') 
UNION SELECT Sender AS amico FROM amicizie WHERE (Receiver = '$IDutente') AND (Friend = '1'))";
//....
?>
tu hai due tabelle "utenti" e "amicizie", giusto?
quello che non capisco (ma può essere la mia poca esperienza) è perchè fai la UNION sulla stessa tabella "amicizie", cioè unisci la tabella su se stessa.
sbaglio o tu vorresti estrarre quel/quelli nickname dalla tab "utenti" che nella tabella "amicizie" che abbiano il Sender=$IDutente o il Receiver=$IDutente e il campo Friend =1 ?
non potresti fare così
PHP:
<?php
//......
$sql="SELECT nickname FROM utenti 
WHERE IDutente = ALL (SELECT Receiver AS amicoR, Sender AS amicoS FROM amicizie WHERE (Sender = '$IDutente' OR Receiver = '$IDutente')
AND Friend = '1')";
//......
?>
prova, al massimo non funzia, allora spera in qualcuno più esperto di me:book:
 
ciao
scusa ma non capisco bene (premetto che non sono molto esperto di mysql).
PHP:
<?php
//....
$sql="SELECT nickname FROM utenti 
WHERE IDutente = ALL (SELECT Receiver AS amico FROM amicizie WHERE (Sender = '$IDutente') AND (Friend = '1') 
UNION SELECT Sender AS amico FROM amicizie WHERE (Receiver = '$IDutente') AND (Friend = '1'))";
//....
?>
tu hai due tabelle "utenti" e "amicizie", giusto?
quello che non capisco (ma può essere la mia poca esperienza) è perchè fai la UNION sulla stessa tabella "amicizie", cioè unisci la tabella su se stessa.
sbaglio o tu vorresti estrarre quel/quelli nickname dalla tab "utenti" che nella tabella "amicizie" che abbiano il Sender=$IDutente o il Receiver=$IDutente e il campo Friend =1 ?
non potresti fare così
PHP:
<?php
//......
$sql="SELECT nickname FROM utenti 
WHERE IDutente = ALL (SELECT Receiver AS amicoR, Sender AS amicoS FROM amicizie WHERE (Sender = '$IDutente' OR Receiver = '$IDutente')
AND Friend = '1')";
//......
?>
prova, al massimo non funzia, allora spera in qualcuno più esperto di me:book:
Dice questo:
PHP:
Error!Operand should contain 1 column(s)
però ti ringrazio tantissimo di averci provato! :D
Se qualcun'altro ha la soluzione e sa come potrei fare mi farebbe felicissima ad aiutarmi!!
 
ciao
sembrerebbe che ci voglia una colonna sola, se non arriva qualche altro esperto, prova a correggere amicoR e amicoS in amico

PHP:
<?php 
//...... 
$sql="SELECT nickname FROM utenti  
WHERE IDutente = ALL (SELECT Receiver AS amico, Sender AS amico FROM amicizie WHERE (Sender = '$IDutente' OR Receiver = '$IDutente') 
AND Friend = '1')"; 
//...... 
?>
oppure prova di brutto a mettere

PHP:
<?php 
//...... 
$sql="SELECT nickname FROM utenti  
WHERE IDutente = ALL (SELECT * FROM amicizie WHERE (Sender = '$IDutente' OR Receiver = '$IDutente') 
AND Friend = '1')"; 
//...... 
?>

dimenticavo nell'ultima prova anche * AS amico
 
Non funziona così :( non è che devo fare delle query separate? Solo che sto facendo delle prove nel database, ma non ne vengo a capo :( continua a dirmi che l'operatore deve contenere una colonna... :(
Edit: ho risolto per query separate... Due liste separate... Almeno funziona!
 
Ultima modifica:

Discussioni simili

M
Risposte
2
Visite
2K
HTML e CSS
Membro cancellato 26246
M