コメントを検索しようとするカスタム モジュールを作成します。次のような 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");
理想的には、これは以下を返すはずです:
ただし、次のようになります。
何らかの理由で、「comment.nid」の結果ではなく、「associated_client」の結果のみが返されます。これが私が働きたいという完全な声明です。私はそれがSMHの瞬間であることを知っていますが、どんな助けも素晴らしいでしょう.
リクエストごとに、返される配列を循環するために使用しているコードは次のとおりです。
foreach($client_comment as $item) {
print_r($item);
print '<br /><br />';
}
すべてのデータを個別に画面に出力する 2 つのクエリを次に示します。これら 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 />';
}