1

Hello iam new to joomla creating a module mod_testimonial. I this have put the data into $rows = $db->loadObjectList(); from the helper file,

and the the data in the $rows after echo is

Array
(
    [0] => stdClass Object
        (
            [name] => james
            [testimonial] => Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
            [regdate] => 2013-12-31 13:24:29
            [id] => 37
        )

    [1] => stdClass Object
        (
            [name] => Tom
            [testimonial] => Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
            [regdate] => 2013-12-31 14:45:56
            [id] => 38
        )

    [2] => stdClass Object
        (
            [name] => Alyson
            [testimonial] => is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s
            [regdate] => 2014-01-03 14:52:09
            [id] => 42
        )

)

in my default.php file the i had fetched the data from array as like this.

 <p><?php print_r($rows[0]->testimonial);?><span class="testimonial-by"> —<?php print_r($rows[0]->name);?>,<?php echo date('M Y',strtotime($rows[1]->regdate)); ?>,</span></p>



  <p><?php print_r($rows[1]->testimonial);?><span class="testimonial-by">—<?php print_r($rows[1]->name);?>,<?php echo date('M Y',strtotime($rows[2]->regdate)); ?>,</span></p>



<p><?php print_r($rows[2]->testimonial);?><span class="testimonial-by">—<?php print_r($rows[2]->name);?>,<?php echo date('M Y',strtotime($rows[0]->regdate)); ?>,</span></p>

my helper file is

static function getRecord($params)
    {

        $db = JFactory::getDBO();
        $query = "SELECT name,testimonial,regdate,id FROM #__testimonial WHERE published = '1' AND featured='1' ";
        $db->setQuery( $query);
        $rows = $db->loadObjectList();
        return $rows;
    }

.Till here its all okk but if i will unpublish or unfeatured the data from the back end it will raise an error like this

Notice: Undefined offset: 2 in modules\mod_testimonial\tmpl\default.php on line 37

Notice: Trying to get property of non-object in modules\mod_testimonial\tmpl\default.php on line 37
File not found

i know this is because there is no

offset [2] => stdClass Object
        (
            [name] => Alyson
            [testimonial] => is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s
            [regdate] => 2014-01-03 14:52:09
            [id] => 42
        )

i want to give a proper loop so that this problem skips and i do not need to change my template.

please help me out very much frusted tried all the stuffs. thankyou

  • check the array have value then only access its index value – Jobin Jan 08 '14 at 12:21
  • yes thanks for that , but how to get that array in a loop so that it gets a continuity and shows the data which were available. i have tried the for each loop but no change , totally blank please help me out. – racial cortis Jan 08 '14 at 12:29
  • possible duplicate of [Reference - What does this error mean in PHP?](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – Sumurai8 Jan 08 '14 at 14:12

1 Answers1

1

Try this,

on your helper file.

function getRecord($params)
    {

        $db = JFactory::getDBO();
        $query = "SELECT name,testimonial,regdate,id FROM #__testimonial WHERE published = '1' AND featured='1' ";
        $db->setQuery( $query);
        return $db->loadObjectList();

    }

In your module file mod_testimonial.php have something like

$data = helperClassname :: getRecord($param);

On your default.php have something like.

if(sizeof($data) > 0){

foreach($data as $key=>$value){

echo "<br/>Name".$value->name;
}

}

for more about module structure and calls check this sample banner slide show module

Hope its helps..

Jobin
  • 8,238
  • 1
  • 33
  • 52