Jump to content

Can you help me to solve a php problem?


ivanella

Recommended Posts

Hi i'm italian so i don't speak english well...

 

I must do a script... but i'm not expert...

 

The php script has to crate a list of my site members showing the fields "ID" and "NAME" of "USER" table in DATABASE.

 

It's difficult becausa the script has to show for each user the number of votes.

 

The number of votes has to be calculated for each user counting the number of ROWS in table "VOTI" that contain in the field "UserID" the "ID" of user.

 

I know, it's difficult, but i hope there is someone that can help me....

 

Thanks...

Link to comment
Share on other sites

first of all thanks for help....

 

I didn't explain well what i need..... because is so comlex for me....

 

In DATABASE i have:

 

table "USER" with ures information like "ID" and "NOME"

 

table "VOTI" with field like "COMMENTOID" and "USERID" that say wich user has voted for the comment.

 

table "COMMENTI" with field "COMMENTOID" e "USERID" that say wich user has insert the comment.

 

The Script has to take "ID" and "NOME" for each member from table "USER", see from table "COMMENTI" what are the comments the user has insert and find from table "VOTI" how many times a comment insert from him  has been voted.

 

Then create a list of user whit  the number of  votes he recived to his comments....

 

It's so difficoult ...help me please....

Link to comment
Share on other sites

I tried this Query:

 

$sql = "SELECT UserID ,Name,count(*) AS numero_commenti

FROM consigli_User AS u JOIN consigli_Comment AS c JOIN consigli_ThankfulPeople AS v

ON u.UserID=c.UserID

AND c.UserID=v.UserID

AND c.CommentID=v.CommentID

GROUP BY Name

ORDER BY numero_commenti DESC

 

";

 

while ($row = mysql_fetch_row($sql)) {

echo 'ID: ', $row[0] , ' Nome: ', $row[1] , "\n";

}

 

but I recive this error:

 

mysql_fetch_row(): supplied argument is not a valid MySQL result

 

can you help me?

 

thanks....

Link to comment
Share on other sites

GROUP BY must contain all the column names that are NOT aggregated

 

so I suggest that since UserID and Name should be 1 to 1 that you do this

 

$sql = "SELECT UserID ,max(Name) AS UserName,count(*) AS numero_commenti

FROM consigli_User AS u JOIN consigli_Comment AS c JOIN consigli_ThankfulPeople AS v

ON u.UserID=c.UserID

AND c.UserID=v.UserID

AND c.CommentID=v.CommentID

GROUP BY UserID

ORDER BY numero_commenti DESC

";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.