prestashop模块显示警告:mysql_fetch_assoc()期望参数1是给定的资源数组


prestashop module showing Warning: mysql_fetch_assoc() expects parameter 1 to be resource, array given

我在prestshop做一个自定义模块。在我的php文件中有这样的函数

 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');
  }

这段代码背后的概念是将所有的值存储在一个数组中,并在视图文件(smarty模板)中获取它们。

当我执行print_r($result);它显示的是数组。值是这样的

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

但是从下一行开始显示Warning: mysql_fetch_assoc() expects parameter 1 to be resource, array given in filename.php line number

这样的错误

在我的。tpl文件(视图文件)我有代码,我想得到的值,如

<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>

所以有人能告诉我为什么我得到这个错误以及如何解决这个问题?任何帮助和建议将是非常感激的。由于

这里直接将您的$result分配给smarty template。因为它已经是array格式。

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

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