Jump to content

[SOLVED] showing two arrays with the same data


Recommended Posts

Hi,

I have the database like this

 



CREATE TABLE IF NOT EXISTS `ps_pagenames` (
  `page_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `page_name` varchar(120) NOT NULL,
  `page_type` varchar(120) NOT NULL,
  PRIMARY KEY (`page_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8  ;


INSERT INTO ``ps_pagenames` (`page_id`, `page_name`, `page_type`) VALUES
(1, 'home_page', 'index'),
(2, 'product_page', 'product'),
(3, 'category_page', 'category');


Now I wanted to get the last inserted values from the database. So for that I made the query like this

 

  


  $pages_query = 'SELECT * FROM `'._DB_PREFIX_.'pagenames` ORDER BY  `page_id` DESC LIMIT 0 , 1';    
    $query_result = Db::getInstance()->executeS($pages_query);

    Now when I tried to check the fetched values by using 


    print_r($query_result);

    It showed me the same array two times like this

    

    


Array
(
    [0] => Array
        (
            [page_id] => 3
            [page_name] => category_page
            [page_type] => category
        )


)


Array
(
    [0] => Array
        (
            [page_id] => 3
            [page_name] => category_page
            [page_type] => category
        )


)

Even I tried to use foreach loop. but still its showing the above array.

So can someone kindly tell me how to fix this issue.I want only one array with the values. Any help will be really appreciable. Thanks

Edited by vekia (see edit history)
Link to comment
Share on other sites

ok i understand,

so, it looks like there is some loop, maybe for? foreach?

can you show code of your function, where you use it?

 
Hi Vekia,
I got the solution. Actually  I had done a mistake by doing two display Hooks like this
 
public function hookLeftColumn($params)
  {
    return $this->hookRightColumn($params);
  }


  public function hookRightColumn($params)
  {
    global $cookie, $smarty;
    $defaultLanguage = (int)(Configuration::get('PS_LANG_DEFAULT'));
    $smarty->assign('defaultLanguage', $defaultLanguage);
    $this->_hookCommon($params);
    return $this->display(__FILE__, 'template.tpl');
  }
  
  and inside hookRightColumn($params) I had made print_r($query_result), as you can see I have assigned two hooks to the template thats why print_r($query_result) showed the array two times. Thank you for your suggestion. Now you can make this issue as resolved :)
Edited by prestashop_newuser (see edit history)
Link to comment
Share on other sites

×
×
  • Create New...