编写自定义模块尝试查找评论。我有一个SQL语句如下:
$client_comment = db_query("SELECT comment.subject AS comment_subject,
comment.cid AS cid,
comment.nid AS comment_nid,
comment.created AS comment_created
FROM
{comment} comment
INNER JOIN {node} node_comment ON comment.nid = node_comment.nid
INNER JOIN {field_data_field_associated_client} associated_client ON comment.cid = associated_client.entity_id
WHERE (( (associated_client.field_associated_client_nid = '$nid')
OR (comment.nid = '$nid') )
AND (comment.status <> '0')
AND (node_comment.status = '1') )
ORDER BY comment_created DESC
LIMIT 10 OFFSET 0");
理想情况下,这应该返回以下内容:
但是,我得到以下信息:
出于某种原因,它只返回“associated_client”结果而不是“comment.nid”结果。这是我想开始工作的完整声明。我知道这是一个 SMH 时刻,但任何帮助都会很棒。
根据请求,这是我用来循环返回数组的代码:
foreach($client_comment as $item) {
print_r($item);
print '<br /><br />';
}
这是 2 个查询,它们分别将所有数据打印到屏幕上。我想将这两个查询合并为 1 个查询:
$client_comment = db_query("SELECT comment.subject AS comment_subject, comment.cid AS cid, comment.nid AS comment_nid, comment.created AS comment_created
FROM
{comment} comment
INNER JOIN {node} node_comment ON comment.nid = node_comment.nid
WHERE (( (comment.status <> '0') AND (node_comment.status = '1') AND (comment.nid = '$nid') ))
ORDER BY comment_created DESC
LIMIT 10 OFFSET 0");
// Get the comments associated TO the client from Caregiver node.
$client_associated_comment = db_query("SELECT comment.subject AS comment_subject, comment.cid AS cid, comment.nid AS comment_nid, comment.created AS comment_created
FROM
{comment} comment
INNER JOIN {node} node_comment ON comment.nid = node_comment.nid
INNER JOIN {field_data_field_associated_client} associated_client ON comment.cid = associated_client.entity_id
WHERE (( (comment.status <> '0') AND (node_comment.status = '1') AND (associated_client.field_associated_client_nid = '$nid') ))
ORDER BY comment_created DESC
LIMIT 10 OFFSET 0");
foreach($client_comment as $item) {
$client_comment_array[] = $item;
}
foreach ($client_associated_comment as $item) {
$client_comment_array[] = $item;
}
foreach($client_comment_array as $item) {
print_r($item);
print '<br /><br />';
}