2016-08-17 76 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

回答

相关问题