473,503 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Incrementing The number of posts

3 New Member
Hii.

Im just writng a script for making a discussion forum...ALl things are working..

but i want in the first page to dispaly the number of comments on each topic.I use the mysql query SELECT COUNT but it dosnt displat anything..

sometimes i get a messgae like ResourceID#6..

any body please help me...

Thanks in advance..

The code is listed below..

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include("connectivity.php");
  3. $cnt=mysql_query("select count(iCommentId) from comments where iTopicId='33'");
  4. while($row=mysql_fetch_array($cnt)) {
  5.  
  6. echo("Count: - ".$row["iCommentId"]."<br>");
  7. }
  8.  
  9.  
  10. $qry=mysql_query("select * from topic"); 
  11. $hid=$_REQUEST['hid'];
  12. //$start=0;
  13.  
  14. //echo "$cnt";
  15. ?>
  16.  
  17. <html>
  18. <head>
  19.  
  20. <title>Discussion form</title>
  21. </head>
  22. <body>
  23.  
  24. <h3 align="center">Discussion Forum Using PHP</h3></td><br>
  25. <form name="frm">
  26. <table align="center" border="2" bgcolor="#00FFFF">
  27. <tr><td colspan="11" align="right"><a href="addtopic.php">Add New Topic</a></td></tr>
  28. <tr><td colspan="7" align="center">
  29.  
  30. <tr><td width="30">Si</td>
  31. <td>Topic</td>
  32. <td>Comments</td>
  33. <td>Posted BY</td>
  34. <td>E-mailid</td>
  35. <td>Date</td>
  36.  
  37. </tr>
  38.  
  39. <?php
  40. $si=1;
  41. while($obj= mysql_fetch_object($qry))
  42. {
  43.  
  44. $topc=$obj->vTopic;
  45.  
  46. $dat=$obj->ddate;
  47. $newdate=explode("-",$dat);
  48. $ddate="$newdate[0]-$newdate[1]-$newdate[2]";
  49. echo
  50.  
  51.     "<tr>
  52.         <td>$si</td>
  53.         <td><a href=\"viewcomments.php?hid=$obj->iTopicId\" style=\"text-decoration:none\">$topc          </a></td>
  54.         <td>Comets</td>
  55.         <td>$obj->cPostedBy</td>
  56.         <td>$obj->cemail</td>
  57.         <td>$ddate</td>
  58.     </tr>";
  59.  
  60.     $si++;
  61.  
  62. }
  63. ?>
  64.  
  65. </td>
  66. </tr>
  67.  
  68. </table>
  69. </form>
  70. </body>
  71. </html>
  72.  
[Please use CODE tags when posting source code. Thanks! --pbmods]
Jun 12 '07 #1
4 1262
ronnil
134 Recognized Expert New Member
you can use mysql_num_rows($qry) to count the number of rows retrieved by your sql statement
Jun 12 '07 #2
jenishkottaram
3 New Member
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include("connectivity.php");
  3.  
  4. $qry=mysql_query("select * from topic"); 
  5. $hid=$_REQUEST['hid'];
  6.  
  7.  
  8. $cnt=mysql_query("select count(iCommentId) from comments where TopicId='33'");
  9. $mycount=mysql_num_rows($cnt);
  10. echo "$mycount";
  11.  
  12. ?>
dude i try dis also..but no change at all...

ill say the problem clearly..ive 2 tables one is for entering the topics and the other is for commets.On clicking the topics d link ll pass 2 d commenst..now i wants in the first page itself near the topic we need to display the no: of comments on each topic..
Jun 12 '07 #3
ronnil
134 Recognized Expert New Member
remove the count() in your select statement :)

you can also try "select count(iCommentId) as num_comments from comments where TopicId=33"

then you can fetch the result with by referring to num comments

$row_obj->num_comments

or if retrieving arrays

$row_arr['num_comments']
Jun 12 '07 #4
jenishkottaram
3 New Member
dude ..thanx.....

itz working...


and the code is..

$cnt=mysql_query("select * from comments where iTopicId='33'");
$mycount=mysql_num_rows($cnt);

echo $mycount;
Jun 12 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2559
by: Tom | last post by:
Anyone help on this? PHP/MySQL I have a repeat region displaying records from orders in a CSV format: CalJoe33,18,08/23/2004,FED EX,PREPAID,WEBSITE,CA,Book,25.95,??? CalJoe33,18,08/23/2004,FED...
3
2873
by: Mothra | last post by:
Here's what I'm trying to do (kill off old Unix logins): --------------------- $i=0; while (<$who>) { chomp($_); my @line = split(/\s+/, $_); # Split it into an array next unless ($line...
2
420
by: brian | last post by:
Hi, before coming to .NET, I utilized regular expressions mostly in JScript / JavaScript and also in my favorite text editor: TextPad (www.textpad.com) I don't know about JScript/JavaScript, but...
2
2545
by: Payson Books | last post by:
Where can I find some info on grabbing the recordID of the last record, incrementing it by one, and using the new number in a new record.
53
4730
by: subramanian100in | last post by:
I saw this question from www.brainbench.com void *ptr; myStruct myArray; ptr = myArray; Which of the following is the correct way to increment the variable "ptr"? Choice 1 ptr = ptr +...
9
6509
by: Lilbrat | last post by:
Im not finding anything similar in the Posts so correct me if Im wrong... Im real new to programing in Access (Been a while since I programed in anything). The question I have is.. How do you...
8
1522
by: TXpugslave | last post by:
And here it is. I'm just, JUST learning how to use perl, and how to do any sort of programming in general. I'm trying to self-teach and have read a book on C programming and wanted to try PERL. I'm...
1
3493
by: asandiego | last post by:
Hey guys, this is my first post here but have been checking this site a lot for anything I need. I hope someone can lead me to what I should do or just an idea to what can be done. What I'm...
6
2582
by: John | last post by:
I have written a VB.NET DLL that is called by a third party program. If I make any changes in the DLL and then try to replace my DLL file the third party program will abort, saying that the DLL...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7011
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4689
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
401
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.