2016-08-17 49 views
-1

如何在下一個項目的查詢中添加逗號?在問題中添加更多詳細信息。如何在下一個項目的查詢中添加逗號?

// Indented the codes to make it more readable 
$participants = [602, 600]; 

$query  = array(); 
$query[] = 'INSERT INTO ' . 
      $db->nameQuote('#__social_conversations_participants'); 
$query[] = '(' . $db->nameQuote('conversation_id') .',' . 
      $db->nameQuote('user_id') . ',' . $db->nameQuote('state') . ')'; 
$query[] = 'VALUES'; 
foreach($participants as $userId){ 
    $query[] = '(' . $db->Quote($conversationId) . ',' . 
        $db->Quote($userId) . ',' . $db->Quote(1) . ')'; 

//這是行不通的,因爲下一個()在這種情況下總是返回 假

// Indented the codes to make it more readable 
    if(next($participants) !== false){ 
     $query[] = ','; 
    } 
} 
// Glue query back. 
$query = implode(' ' , $query); 
var_dump($query);exit; 
+0

心去你的問題。 – Darren

+0

是什麼數據庫庫?它有參數化查詢嗎? – Isaac

+0

你爲什麼要構建一個這樣的查詢,爲什麼把它分解爲一個數組來重新加入呢? – 2016-08-17 03:26:19

回答

相關問題