Bonjour,
Je suis en train de programmer un petit script en PHP pour faire un forum très simple. J'ai deux tables MySQL à savoir topics et posts. A l'arrivée sur le forum je voudrais montrer les 'topics' et le nombre de 'posts' que chacun contiennent. Lorsque je veux compter les 'posts' avec select count le navigateur affiche Object id #x au lieu du nombre de posts comptés.
Voici le fragment de code en question :
Merci d'avance pour votre aide!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 $display_block = "<table cellpadding=3 cellspacing=1 border=1> <TR> <TH> Topic title </TH> <TH> # of posts </TH> </TR>"; while($topic_info = mysqli_fetch_array($get_topics_res)){ $topic_id = $topic_info['topic_id']; $topic_title = $topic_info['topic_title']; $topic_time = $topic_info['topic_time']; $topic_owner = $topic_info['topic_owner']; $get_num_posts = "select count(post_id) from posts where topic_id=$topic_id"; $get_num_posts_res = mysqli_query($conn, $get_num_posts); $display_block .= " <TR> <TD><a href = 'showtopic.php?topic_id = $topic_id'> <STRONG> $topic_title </STRONG></A><BR> CREATED on $topic_time by $topic_owner</TD> <TD align = center> $get_num_posts_res </TD> </TR>\n";}
webrider
Partager