Comments Compare + Count

16 posts by 2 authors in: Forums > CMS Builder
Last Post: July 16, 2010   (RSS)

By ILLUME-MEDIA-LABS - July 12, 2010 - edited: July 12, 2010

Hi,

SO I have a question. My articles table n comments table are separate. How can I do query and connect comments with articles to do count...on the category page. For the article page...I did this and it works:

// load comments
list($countRecords, $countMetaData) = getRecords(array(
'tableName' => 'comments',
'allowSearch' => false,
'where' => "commentValue = '". mysql_real_escape_string( $_SERVER['REQUEST_URI']) ."' AND approved = 0",

));


<?php @$count = 0; ?><?php foreach ($countRecords as $record): ?><?php @$count++; ?><?php endforeach ?> <?php echo @$count; ?>


How would I write the code so the query compares the article url with the commentValue url and returns the total count?

Thanks!

Re: [Illume Magazine] Comments Compare + Count

By Jason - July 13, 2010

Hi,

There may be an easier way to do this. First, can you give me a list of all of the fields that appear in your articles and your comments tables?

Do these two tables only link on the commentValue field? If so, can you give me an example of what the information in this field looks like?

Let me know and we'll get something figured out.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Comments Compare + Count

Hi Jason,

Heres what you requested. The comment value is the article url. ie: /zine/articleDetail.php?Clinton-Condemns-World-Cup-Terror-13111

Comments Table
Approved checkbox
Title textfield
Name textfield
Email textfield
Comment wysiwyg
commentValue textfield


Article Table
Title textfield
Category list
Add To Slideshow checkbox
External Link textfield
Hidden checkbox
Approved checkbox
Featured checkbox
Date date
Author textfield
Twitter Search Single Keyword textfield
Tag Cloud Multiple Keywords textfield
Pull Quote textbox
Summary textbox
Content wysiwyg
Article Image upload
Slideshow Image upload
In Pictures upload
File Attatchments upload
Photo Essay Images upload
MP3 URL textfield
Video Embed Code textbox
Video Caption textfield

Re: [Jason] Comments Compare + Count

Here is an example page where the comments would show up (next to the bubble) so you can get an idea.

http://www.illumemag.com/zine/categoryIndex.php?Column&category=145

When I added your code...the error I received was:

Notice: Undefined variable: articleRecords in /home/content/i/l/l/illumemedia/html/zine/categoryIndex.php on line 146 Warning: Invalid argument supplied for foreach() in /home/content/i/l/l/illumemedia/html/zine/categoryIndex.php on line 146

Re: [Illume Magazine] Comments Compare + Count

By Jason - July 14, 2010

Hi,

This is the only really important part of the code that I sent you:

<?php
$commentValue = "/zine/articleDetail.php?".str_replace("'","-",str_replace(" ","-",$article['title']))."-".$article['num'];
$count = mysql_select_count_from("comments","commentValue='$commentValue'");
?>

This code is meant to go inside your foreach loop. You may have to change the names of the variables ($article) for example to match either what you're using in your database or to match the variables you're using inside your .php page.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Comments Compare + Count

I update the variable, but didnt work.

Re: [Illume Magazine] Comments Compare + Count

By Jason - July 14, 2010

Hi,

If you could attach the .php file you're working with, I can take a closer look.

thanks
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Comments Compare + Count

Here is the file. Thank you jason!
Attachments:

categoryindex.php 18K

Re: [Illume Magazine] Comments Compare + Count

By Jason - July 14, 2010

Hi,

I've taken a look. There doesn't seem to be any errors in the code. What's happening though is that the number stored in $count is never being outputted. You need to use this where ever you want the number of comments to be outputted:

<?php echo $count; ?>

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/