php - Using COUNT in a MYSQL Statement -


users can posts , posts can have comments , want number of comments made in users posts.

posts table:

id | content | foto | likes | genious | user_id | timepost | youvideo |

comments table:

id | users_id | posts_id | content | timecomment |

$stmt = $mysqli->prepare("select count(comments.id) comments inner join posts on      posts.id=comments.users_id posts.user_id=? ");  $stmt->bind_param('i',$_session['id']); $stmt->execute(); $stmt->bind_result($comentarios); $stmt->fetch(); $_session['comentarios']=$comentarios; 

i suppose, have post_id foreign key in comments table.

if want comments, made on users posts, try this:

select     count(comments.id)     comments inner join     `posts` on     comments.post_id=posts.id ,     `posts`.user_id=? 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -