2011-12-14 5 views
0

変形例私はこのクエリPHPのするmysql_query/

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

を持っている私も、この変数を持っている:

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

私は($ MYVARからSELECTに値を追加)このように私の問合せをリライトしたいです:

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

どうすればいいですか? そして、元のクエリ(= $ result)に書き込むことなくクエリを変更する関数を書くことは可能ですか?

答えて

0

implode()を使用してテーブルを連結することができます。

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

これは

SELECT p.`id_product`, pl.`description`set, 
    pl.`information`,information2,information3 FROM x 
+0

が生成されます、それは私を助けあなたの答えをありがとうございました。 $ resultに書かずに同じことをすることはできますか?例:$ result = newresult($ result); – prestarocket

+0

はい、新しい変数insetadを作成してください。 '$ newresult = SELECT p.id_product、pl.description set、pl.information、$ tables FROM x" 'です。 – kba

関連する問題