Page 1 of 1

At the risk of looking totally silly

Posted: Sun Sep 09, 2007 11:30 pm
by tjay
Ok so we are here to learn to code J1.5 that means looking silly should be ok right? so take it easy on me.
I am trying to actually write a phpbb3 latest post module for J1.5

Steps to my approach
get a module skeleton to work and install. (thanks to the wiki and the 1.5 module hello world) done
Modify the helper.php to hold a basic SQL query that hits a hardcoded phpbb3 table in my joomla database and return it in a list
Not Done

Future load in all the neat parameters to make the module useful  not even thinking there yet.

here is the problem, and it will most likely provide some of you with a chuckle but my function returns "Array" and nothing else

So here is the code

Code: Select all

class modHelloWorldHelper
{
    /**
     * Retrieves posts from phpbb3
     *
     * @param array $params An object containing the module parameters
     * @access public
     */
    function getPosts( $params )
    {

       global $mainframe;

      $db         =& JFactory::getDBO();

$query = 'SELECT phpbb_posts.post_subject,phpbb_posts.post_text' .
         ' FROM phpbb_posts' .
         ' WHERE phpbb_posts.post_approved =  1';
      $db->setQuery($query, 0, 5);
      $rows = $db->loadObjectList();

      $i      = 0;
      $lists   = array();
      foreach ( $rows as $row )
      {
         $lists[$i]->text = htmlspecialchars( $row->phpbb_posts.post_subject );
         $i++;
      }

      return $lists;
    }
}
?>

Re: At the risk of looking totally silly

Posted: Mon Sep 10, 2007 1:21 am
by DeanMarshall
Hi,

I think the problem is the arrow notation you are using.
Are you coming from a Perl background by any chance?
This is probably nearer the mark - though undoubtedly not perfect.

Code: Select all

      $lists[$i]['text'] = htmlspecialchars( $row['post_subject'] );


I'm not sure whether your $row is an associative array (with named keys)
or a standard array with numeric keys so there is still some doubt in my mind
as to whether this line is right or not.

Dean

Re: At the risk of looking totally silly

Posted: Mon Sep 10, 2007 10:21 am
by Pentacle
Don't call yourself silly. If you think like that, we all are silly now. :D

My advice is:

change the query like this:

SELECT phpbb_posts.post_subject AS phpbb_subject

and change $row->phpbb_posts.post_subject to $row->phpbb_subject.

Hope it helps,
Ercan.

Re: At the risk of looking totally silly

Posted: Tue Sep 11, 2007 2:53 am
by jalil
yeah, don't silly yourself. i tetsed my fresh made component, made changes and thought it fit to be tested so upload/install it all to my test site, which deletes the working version, and leaves me with a faulty version, with no copy of the correct initial version.
now thats is silly.

my question is is SQL able to take database name and object name of the same name without getting confused (as in the code above ) ?

Re: At the risk of looking totally silly

Posted: Tue Sep 11, 2007 3:03 am
by louis.landry
tjay,

the string "Array" is what is output when you print/echo an array variable in PHP.  If you want to see the contents of the array try doing,

Code: Select all

var_dump($variable);


or

Code: Select all

print_r($variable);


You may be surprised what you get.

Louis