Jump to content

Array to string conversion


Recommended Posts

hi...

i am assign the the variable in java scripts like as

<script type="text/javascript">
var my_var = "{$my_var1}";
</script>

here $my_var1 is result set of database array then its give me the.
 

PHP Notice:  Array to string conversion in

how can i assign this result set in java script varibale

thanks

 

Link to comment
Share on other sites

thank you for your response

 

 

My code is something like this

 

public function hookHeader()
{
$my_var1 = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'mymodule`');
$this->context->smarty->assign(array(
'my_var1' => $my_var1,
));
return $this->context->smarty->fetch($this->local_path.'views/templates/hook/header.tpl');
}

 

 

$my_bar1 return this array
 

 
Array
(
    [0] => Array
        (
            [id_mymodule] => 1
            [value1] => value1
            [value2] => value2
            [value3] => value3
            [value4] => value4
            [value5] => value5
            [date_add] => 2016-07-12 08:14:33
            [date_upd] => 2016-07-12 08:14:33
        )
 
    [1] => Array
        (
            [id_mymodule] => 2
            [value1] => value1
            [value2] => value2
            [value3] => value3
            [value4] => value4
            [value5] => value5
            [date_add] => 2016-07-12 08:15:04
            [date_upd] => 2016-07-12 08:15:04
        )
)

 

 

 

 

then after i assign the header.tpl file like this

 

<script type="text/javascript">
var my_var = "{$my_var1}";
</script>

 

 

 

after its give me error 

 

PHP Notice: Array to string conversion in

 

thanks

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

Hi....

Thank you for both  of reply i using this code an thanks for 'Enrique Engblom' idia for using code
 

<script type="text/javascript">
var my_var = [
{foreach from=$my_var1 item=var name=my_var1}
   {
  id_mymodule: {$var.id_mymodule},
value1: '{$var.value1}',
value2: '{$var.value2}',
value3: '{$var.value3}',
value4: '{$var.value4}',
value5: '{$var.value5}',
date_add: '{$var.date_add}',
date_upd: '{$var.date_upd}'
   }
   {if !$smarty.foreach.my_var1.last},{/if} 
{/foreach}
];
</script>

 

 

its perfect wroking

thanks

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...