up vote 0 down vote favorite
share [g+] share [fb]

I have this query

$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT p.`id_product`, pl.`description`set, pl.`information`
FROM....

i have also this variable :

$myvar=array('information2','information3')

i want to rewrite my query like this (add values from $myvar to the SELECT) :

$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
    SELECT p.`id_product`, pl.`description`set, pl.`information`,pl.`information2`,pl.`information3`
    FROM....

How can i do this ? And it is possible to write a function for changing the query without write into the original query (=$result) ?

link|improve this question

76% accept rate
feedback

1 Answer

You can concatenate the tables using implode().

$tables = implode(',',$myvar);
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS("
SELECT p.`id_product`, pl.`description`set, pl.`information`,$tables
FROM x");

This will produce

SELECT p.`id_product`, pl.`description`set,
    pl.`information`,information2,information3 FROM x
link|improve this answer
thank you for your answer it helps me. Can i do the same thing without write in $result. Ex : $result=newresult($result); – adokara Dec 14 '11 at 15:49
Yes, just create a new variable insetad. $newresult = SELECT p.id_product, pl.description set, pl.information,$tables FROM x". – Kristian Antonsen Dec 14 '11 at 16:06
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.