2011-12-14 32 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 2011-12-14 15:49:16