Jump to content

Recommended Posts

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

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

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>

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.