cpharry Posted January 1, 2009 Share Posted January 1, 2009 Hi, I have a forum project coming along and I need to make the replies variable that comes up next to the post on the forum view when you can see them all. However I can get it to work so that when a user posts a message then it adds 1 to the "replycount field" but what I cant get is that if I take it out it wont count the number of replies. I know roughly that it has to query the number of records found using the postid from both tables but I cant think of where to put it. Can anyone help. Link to comment https://forums.phpfreaks.com/topic/139088-mysql_num_rows-but-no-space/ Share on other sites More sharing options...
redbrad0 Posted January 1, 2009 Share Posted January 1, 2009 Why not just update the main post? ReplyCount=ReplyCount+1 Most software stores the reply count for speed issues. You can just do a count and even just include that in your main query select topicid, topicsubject, (select count(id) as TotalReplys from ReplyTable where post=topicid) as TotalReplys from Topics where topic=xxxx Link to comment https://forums.phpfreaks.com/topic/139088-mysql_num_rows-but-no-space/#findComment-727470 Share on other sites More sharing options...
cpharry Posted January 1, 2009 Author Share Posted January 1, 2009 Shall I post the page that I am working on and then you will knoe what I mean, I now that I can count it but I cant seem to word it because the count that I am using at the moment is under the main query block. Link to comment https://forums.phpfreaks.com/topic/139088-mysql_num_rows-but-no-space/#findComment-727475 Share on other sites More sharing options...
cpharry Posted January 1, 2009 Author Share Posted January 1, 2009 Thats what I have so far but where would I put the count ? <?php $host="localhost"; // Host name $username="simnetwo"; // Mysql username $password="Taken OUT"; // Mysql password $db_name="simnetwo_test"; // Database name $tbl_name="posts"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $ID=$_GET['id']; $sql="SELECT * FROM $tbl_name WHERE ForumID='$ID'"; $result=mysql_query($sql); $sql2="SELECT * FROM posts WHERE ForumID='$ID'"; $result2=mysql_query($sql2); ?> <body> <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topics</strong></td> <td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td> <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td> <td width="13%" align="center" bgcolor="#E6E6E6"> </td> </tr> <?php while($rows=mysql_fetch_array($result)){ // Start looping table row $postidid = $rows['ID']; ?> <tr> <td bgcolor="#FFFFFF"><a href="view_post.php?id= <? echo $rows['ID']; ?>"> <? echo $rows['Topic']; ?></a><BR></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['ViewCount']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo mysql_num_rows($result3); ?></td> <td align="center" bgcolor="#FFFFFF"> </td> </tr> <?php // Exit looping and close connection } mysql_close(); ?> <tr> <td align="right" bgcolor="#E6E6E6"> </td> <td align="right" bgcolor="#E6E6E6"> </td> <td align="right" bgcolor="#E6E6E6"> </td> <td align="right" bgcolor="#E6E6E6"> </td> </tr> </table> </body> </html> Link to comment https://forums.phpfreaks.com/topic/139088-mysql_num_rows-but-no-space/#findComment-727477 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.