How to resolve “Notice: Array to string conversion in”

I can’t figure out why I am receiving the following error Notice: Array to String conversion in ‘path’ line 462. Below is the code for line 462.

public function fetchOneBrg(array $conditions){

        $db = Core::getInstance();
        $sql = "SELECT * FROM ".USERS_BRG." WHERE ";
        $params = array();
        $i=0;
   foreach ($conditions as $column => $value) {
     if (preg_match('/^[a-z-.-_]+$/', $column)) {
        if($i !=0){
                $sql .= " AND ";
            }
    $sql .= "$column = ?";
    $params[] = $value;
    $i++;
}

}
$res = $db->dbh->prepare($sql);
Line 462: $res->execute(array_values($params));
return $res->fetch(PDO::FETCH_ASSOC);

$ststres = $db->dbh->prepare("SELECT * FROM ".USERS_STATS." WHERE user_id = :uID ORDER BY id DESC LIMIT :zero, :forty");                
$ststres->bindParam(':uID',$udata['id'],PDO::PARAM_INT);
$ststres->bindValue(':zero',0,PDO::PARAM_INT);
$ststres->bindValue(':forty',40,PDO::PARAM_INT);                        
$ststres->execute(); 
$ststres=$ststres->fetchAll(PDO::FETCH_ASSOC);

I suspect it is the code above being passed in as a string to during the call array([‘id’=>$ststres[ststval].to_id] below in Smarty. Doing a var_dump returns strings in array. How to resolve this and why is the string conversion happening on the ID’s?

This is the call to the function:
{assign var=‘brgdatas’ value=$brgObj->fetchOneBrg(array([‘id’=>$ststres[ststval].to_id]))}

Thank you for your help.

I don’t think this is giving you the desired results:

[php]array([‘id’=>$ststres[ststval].to_id])[/php]

The brackets are creating a secondary array. For example:

[php]
$a = array([‘id’=>0]);
var_dump($a);

/* result:

array (size=1)
0 =>
array (size=1)
‘id’ => int 0
*/
[/php]

I believe you want to remove the brackets?

[php]array(‘id’=>$ststres[ststval].to_id)[/php]

Thank you for your replay, but I have tried that before and I received the following error.

{assign var='brgdatas' value=$brgObj->fetchOneBrg(array('id'=>$ststres[ststval].to_id))}" - Unexpected "=>", expected one of: "","" , ")"'

How do I resolve this error?

You will just have to figure out the best way to deal with smarty syntax. I’m not very familiar with smarty. Perhaps something like this would be best (but I know the PHP tags can be disabled)

{php}$this->assign('brgdatas', $brgObj->fetchOneBrg(array('id'=>$ststres[ststval].to_id)));{/php}

Another possibility but I cannot test :slight_smile:

See:
http://www.smarty.net/docs/en/language.syntax.variables.tpl

{assign var='brgdatas' value=$brgObj->fetchOneBrg(array['id'=>$ststres[ststval].to_id])}

Oh, I noticed that is what you tried :slight_smile: Perhaps there is a problem with $ststres? If you do this does it still error?

{assign var='brgdatas' value=$brgObj->fetchOneBrg(array['id'=>0])}

Thanks for your help. It really helped the end result was the code below.

{assign var=‘brgdatas’ value=$brgObj->fetchOneBrg([‘id’=>$ststres[ststval].to_id])}

Ahh yes… the array keyword is unnecessary. Great

Sponsor our Newsletter | Privacy Policy | Terms of Service