-1

I am doing a custom module in prestashop. Now in my php file I have the function like

 public function hookHome($params)
  {
    $defaultLanguage = (int)(Configuration::get('PS_LANG_DEFAULT'));
    global $cookie, $smarty;
    $value=array();
    $sql_select="SELECT DISTINCT country_name,country_ISO from "._DB_PREFIX_."storedetails where status='1'";
       $result=Db::getInstance()->ExecuteS($sql_select);
       print_r($result);

      while($row=mysql_fetch_assoc($result))
      {
      $value[] = $row;
  }
       $smarty->assign('array',$value);
       $smarty->assign('default',$defaultLanguage);
     return $this->display(__FILE__, 'storedetails.tpl');
  }

The concept behind this piece of code is storing all the values in an array, and get them in view file(smarty template).

Here when I am doing print_r($result); it is showing the array. The values are coming like this

Array ( [0] => Array ( [country_name] => [country_ISO] => select ) [1] => Array ( [country_name] => Germany [country_ISO] => DE )...

but from next line it is showing error like Warning: mysql_fetch_assoc() expects parameter 1 to be resource, array given in filename.php line number

In my .tpl file(view file) I have the code where I would like to get the values like

<select onchange="selectCountry(this.value)">
    <option value="Select">Select</option> 
     {foreach from=$array item=row}
         <option value="{$row.country_ISO}" id="{$row.country_name}">{$row.country_name}</option>
    {/foreach}
    </select>

So can someone kindly tell me why I am getting this error and how to solve this issue?Any help and suggestions will be really appreciable. Thanks

4

1 回答 1

3

这里直接分配你的$resultto smarty template。因为它已经是array格式了。

$smarty->assign('array',$result);

mysql_fetch_assoc用于迭代SELECT查询的结果,但在您的情况下,您提供array的不是查询的resource输入SELECT

于 2013-05-11T05:11:58.643 回答