Joomla! Discussion Forums



It is currently Wed Nov 25, 2009 4:26 am (All times are UTC )

 


Forum rules

Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.



Post new topic Reply to topic  [ 7 posts ] 
Author Message
Posted: Sun Jan 22, 2006 10:26 am 
User avatar
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sun Jan 22, 2006 10:05 am
Posts: 6
Location: Eindhoven, The Netherlands
The "latest comment"-module interacts with the AkoComment-component to display the name of the commenter, the title of his/her comment and the first 100 signs of the comment. I also want it to display the title of the content item to which the comment relates. In the source the ID of the content item (stored in the _content table) is known, so basically my question boils down to:
How do I get from the contentid (numerical value) to display the content item title?

For example: John comments on an article "Fishing is stupid" (with the id 61 in the _content table). I want the "latest comments"-module to display: "John (Fishing is stupid): blahdiblah". HOW DO I DO THIS? I can't get it to work... Please help!

_________________
"Recognize, analyze, capitalize!"
  - Brad Gilbert


Last edited by lunarum on Sun Jan 22, 2006 8:21 pm, edited 1 time in total.

Top
  E-mail  
 
Posted: Sun Jan 22, 2006 12:38 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sun Jan 22, 2006 10:05 am
Posts: 6
Location: Eindhoven, The Netherlands
BTW: I got the code looking something like this now:
Code:
$query = "SELECT title AS contentitemtitle FROM #__content "
         . "WHERE id = $row->contentid";

$database->setQuery($query);

So how can I now create a variable $contentitemtitle which holds the title of the content item the comment relates to?
I've already tried adding:
Code:
$contentitemtitle = $database->loadObjectList();

but that doesn't do the trick. It returns "Object id#", although the query (in phpMyadmin) seems to work...
As you can probably notice, I'm not that much of an adept at PHP and SQL, so does somebody have an idea on how to solve this problem?

_________________
"Recognize, analyze, capitalize!"
  - Brad Gilbert


Last edited by lunarum on Sun Jan 22, 2006 8:22 pm, edited 1 time in total.

Top
  E-mail  
 
Posted: Mon Jan 23, 2006 12:21 am 
User avatar
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sun Jan 22, 2006 10:05 am
Posts: 6
Location: Eindhoven, The Netherlands
lunarum wrote:
Code:
$contentitemtitle = $database->loadObjectList();

but that doesn't do the trick. It returns "Object id#", although the query (in phpMyadmin) seems to work...
As you can probably notice, I'm not that much of an adept at PHP and SQL, so does somebody have an idea on how to solve this problem?

OMFG! H4X0R! I did it on my own! Hurray for me! (excuse my enthousiasm) The query I made worked. All I needed to do was change the quoted code to:
Code:
$contentitemtitle = $database->loadResult();

This loads the first cell of the first row of the result of the query in stead of presenting it as an object.
Well, my question is answered now, but thanks anyway!

_________________
"Recognize, analyze, capitalize!"
  - Brad Gilbert


Top
  E-mail  
 
Posted: Tue Feb 14, 2006 1:19 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Thu Sep 22, 2005 2:09 pm
Posts: 17
would you be so kind to post your complete solution?

'cause I am a beginner when it comes to php.

Thanks!

_________________
www.padexx.de


Top
  E-mail  
 
Posted: Tue Feb 14, 2006 4:29 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sun Jan 22, 2006 10:05 am
Posts: 6
Location: Eindhoven, The Netherlands
In the file mod_latestcomment.php I changed the following lines:
Code:
   $content .= "<tr><td valign='top'><img src='modules/mod_latestcomments/bullet.gif' alt=' '/>
<a href=\"index.php?option=content&task=view&id=".$row->contentid."\"> <b>".$row->title."</b></a>";
    $content .= "<br /><font class='smalldark'>".$row->comment."</font>";
    if ($showname) $content .= "<br /><b>Posted by: </b><font class='smalldark'>".$row->name."</font>";
   if ($date) $content.= "<br />[".$row->date."]";
    $content .= "</td></tr>";

to:
Code:
     // second query to find contentitemtitle with the corresponding contentitemid
     $query2 = "SELECT title AS contentitemtitle FROM #__content "
           . "WHERE id = $row->contentid";

     // run second query
     $database->setQuery($query2);
     $contentitemtitle = $database->loadResult();

        // print results to html-code
   $content .= "<tr><td valign='top'><a href=\"index.php?option=com_content&task=view&id=".$row->contentid.
"\"> ".$row->name."</a> <b>(".$contentitemtitle."):</b> ";
    $content .= "<font class='smalldark'>".$row->comment."</font>";
    $content .= "</td></tr>";


This code will publish your latest comments like the aformentioned "John (Fishing is stupid): blahdiblah" (so including the brackets and colon). Hope this'll help you out!

_________________
"Recognize, analyze, capitalize!"
  - Brad Gilbert


Top
  E-mail  
 
Posted: Wed Feb 15, 2006 1:36 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Thu Sep 22, 2005 2:09 pm
Posts: 17
perfect!

Thanks!

_________________
www.padexx.de


Top
  E-mail  
 
Posted: Thu May 04, 2006 4:04 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Mon Dec 05, 2005 5:21 pm
Posts: 6
I was looking to do the same thing. Thanks for doing all the hard work for me. I owe you!


Top
  E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

Quick reply

 



Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group