I have decided to invest in a book that teaches PHP, MYSQL and Apache and I am curently working through it but I have come across a pice that don't work properly and I cannot fix itso I was woundering if you could help me
This is the pice of code that I carnt get to work
| //cerate the display string $display_block = " <table cellpadding=3 cellspacing=3 border=1> <tr> <th>TOPIC TITLE</th> <th># of POSTS</th> </tr>"; while ($topic_info = mysql_fetch_array($get_topics_res)) { $topic_id = $topic_info['topic_id']; $topic_title = stripslashes($topic_info['topic_title']); $topic_create_time = $topic_info['fmt_topic_create_time']; $topic_owner = stripslashes($topic_info['topic_owner']); //get number of posts $get_num_posts = "select count(post_id) from forum_posts where topic_id = $topic_id"; $get_num_posts_res = mysql_query($get_num_posts,$conn) or die(mysql_error()); $num_posts = mysql_result($get_num_posts_res,0,'count(post_id)'); //add to display $display .= " <tr> <td><a href\"showtopic.php?topic_id=$topic_id\"> <strong>$topic_title</strong></a><br> Created on $topic_create_time by $topic_owner</td> <td align=center>$num_posts</td> </tr>"; } //close up the table $display_block .= "</table>"; |
It should show up a topic with how many posts are in it but it only brings up the TOPIC TITLE and # of POSTS bit which are the titles for the coloms.
[addsig]


Again, I'd personally leave that last line out (mysql_num_rows), it's a bit pointless. Also make sure you have some topics in your database..!