ivanella Posted November 24, 2007 Share Posted November 24, 2007 Hi guys i have a problem: in my DATABASE i have 3 tables TABLE 1 name : "consigli_User" fields : "UserID" and "Name" TABLE 2 name : "consigli_Discussion " fields : "AuthUserID" and "CommentID" TABLE 3 name : "consigli_Discussion " fields : "UserID" and "CommentID" i execute the script: $sql = "SELECT UserID,Name,AuthUserID,CommentID,count(*) AS numero_commenti FROM consigli_User AS u JOIN consigli_Comment AS c JOIN consigli_ThankfulPeople AS v ON u.UserID=c.AuthUserID AND c.AuthUserID=v.UserID AND c.CommentID=v.CommentID GROUP BY numero_commenti ORDER BY numero_commenti DESC"; $res=mysql_query($sql) or die ("Query non valida: $sql"); while ($row = mysql_fetch_row($res)) { echo 'ID: ', $row[0] , ' Nome: ', $row[1] , "\n"; } I need to list the user with the numbers of "thanks" recived to their coments by there is an error: Query error: SELECT UserID,Name,AuthUserID,CommentID,count(*) AS numero_commenti FROM consigli_User AS u JOIN consigli_Comment AS c JOIN consigli_ThankfulPeople AS v ON u.UserID=c.AuthUserID AND c.AuthUserID=v.UserID AND c.CommentID=v.CommentID GROUP BY numero_commenti ORDER BY numero_commenti DESC please help me... Quote Link to comment Share on other sites More sharing options...
ivanella Posted November 24, 2007 Author Share Posted November 24, 2007 sorry i made a mistake... TABLE 3 nome tabella: "consigli_ThankfulPeople" Quote Link to comment Share on other sites More sharing options...
LordOrange Posted November 24, 2007 Share Posted November 24, 2007 can you post the whole script Quote Link to comment Share on other sites More sharing options...
ivanella Posted November 25, 2007 Author Share Posted November 25, 2007 this is the woole code.... I tried with this code: ho modificato il codice in: $sql = "SELECT UserID,Name,AuthUserID,CommentID,count(*) AS numero_commenti FROM consigli_User AS u JOIN consigli_Comment AS c JOIN consigli_ThankfulPeople AS v ON u.UserID=c.AuthUserID AND c.AuthUserID=v.UserID AND c.CommentID=v.CommentID GROUP BY numero_commenti ORDER BY numero_commenti DESC"; $res=mysql_query($sql) or die ("Query non valida: $sql <br>Errore: ".mysql_error()); while ($row = mysql_fetch_row($res)) { echo 'ID: ', $row[0] , ' Nome: ', $row[1] , "\n"; } and i have this error: Query non valida: SELECT UserID,Name,AuthUserID,CommentID,count(*) AS numero_commenti FROM consigli_User AS u JOIN consigli_Comment AS c JOIN consigli_ThankfulPeople AS v ON u.UserID=c.AuthUserID AND c.AuthUserID=v.UserID AND c.CommentID=v.CommentID GROUP BY numero_commenti ORDER BY numero_commenti DESC Errore: Column 'UserID' in field list is ambiguous help????? Quote Link to comment Share on other sites More sharing options...
ivanella Posted November 25, 2007 Author Share Posted November 25, 2007 I correct the code: and now the script work.... $sql = "SELECT u.UserID,Name,AuthUserID,c.CommentID,count(*) AS numero_commenti FROM consigli_User AS u JOIN consigli_Comment AS c JOIN consigli_ThankfulPeople AS v ON u.UserID=c.AuthUserID AND c.AuthUserID=v.UserID AND c.CommentID=v.CommentID GROUP BY numero_commenti ORDER BY numero_commenti DESC"; $res=mysql_query($sql) or die ("Query non valida: $sql <br>Errore: ".mysql_error()); but now, how can i show the list of all User showing: UserID, Name, numero_commenti thanks for help.... Quote Link to comment Share on other sites More sharing options...
ivanella Posted November 25, 2007 Author Share Posted November 25, 2007 I tried in this way: echo ' <table border="1"> '; while ($row = mysql_fetch_assoc($res)) { $userID = htmlentities($row['userID']); $Name = htmlentities($row['Name']); $numero_commenti = htmlentities($row['numero_commenti']); echo "<tr> <td>$userID</td> <td>$Name</td> <td>$numero_commenti</td> </tr>"; } echo '</table>'; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.