SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Mar 2009
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    running a query in a custom prestashop page

    Hi guys,

    Has anyone ever managed to do this, create a custom page (not through the admin function to create a page) and have this page run a query to a database to extract data? I've looked through google and can't find any suggestion as how to do this so thought I would ask here. Prestashop uses the 'Smarty' template engine, which to be honest I have no idea on how to use. I have managed to add a new page and the template for the page in the theme (thanks to some nice person who shared their work for all to use).

    It works great for a static page but I need to have it dynamic. I've looked through other template files which use a query but I can't see how it's done. Does anyone have an idea or a link to how to do this?

    Cheers

  2. #2
    SitePoint Addict
    Join Date
    Mar 2009
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess no one has but maybe if I show what I've got so far, someone can help maybe. Basically I've added a table to the database called towns and this table has a list of towns each with an id. All I want to do is show the towns on the page using the code below.

    Right, I have got a result to show but it displays 'array' on the page. Here's my php code

    Code:
    <?php
    
    include(dirname(__FILE__).'/config/config.inc.php');
    
    if(intval(Configuration::get('PS_REWRITING_SETTINGS')) === 1)
        $rewrited_url = __PS_BASE_URI__;
    	
    include(dirname(__FILE__).'/header.php');	
    
    $results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
    			SELECT `town_name`
    			FROM `ps_towns`');
    
    $towns = array();
    
    foreach($results as $result) {
    	$towns[] = $result['town_name'];
    }
    
    echo $towns;
    
    $smarty->display(_PS_THEME_DIR_.'newpage.tpl');
    
    include(dirname(__FILE__).'/footer.php');
    
    ?>

  3. #3
    SitePoint Addict
    Join Date
    Mar 2009
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This topic can be closed as I've managed to sort it myself


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •