Jump to content

Recommended Posts

ok....both these queries pull up topic_id numbers. How would i combine them to where the one combined super query, if you will, will only pull up the ones that BOTH have the same topic_id numbers?

 

SELECT topic_id FROM Topics WHERE topic_id IN (SELECT DISTINCT a.topic_id
FROM Responses a
INNER JOIN (
SELECT topic_id, MAX(create_date) AS maxCreateDate
FROM Responses
WHERE created_by = '$userr'
GROUP BY topic_id ) b
ON a.topic_id = b.topic_id
AND a.create_date > b.maxCreateDate)

 

and

 

SELECT topic_id FROM newreplies WHERE user = '$username' and viewed = '0' "

Link to comment
https://forums.phpfreaks.com/topic/169864-help-with-combing-two-queries/
Share on other sites

i think thats what i want but heres my test script thats not working...

<?php
session_start();
include("caneck.inc");
   
  
$cxn = mysqli_connect($host,$user,$passwd,$dbname)
          or die ("Couldn't connect");


$sql = "SELECT topic_id FROM Topics WHERE topic_id IN (SELECT DISTINCT a.topic_id
FROM Responses a
INNER JOIN (
SELECT topic_id, MAX(create_date) AS maxCreateDate
FROM Responses
WHERE created_by = 'admin'
GROUP BY topic_id ) b
ON a.topic_id = b.topic_id
AND a.create_date > b.maxCreateDate)";  
   $result = mysqli_query($cxn,$sql)
          or die (mysqli_error($result));   
    
   // while there are rows to be fetched...  
   $list = mysqli_fetch_assoc($result);
   
  $ble = "SELECT topic_id FROM newreplies WHERE user = 'admin' and viewed = '0' ";
   $res = mysqli_query($cxn,$ble)
          or die (mysqli_error($cxn));
$ult = mysqli_fetch_assoc($res);		  
$ret = array_intersect($list, $ult);
print_r($list);
echo "<br>";
print_r($ult);		  
?>

 

it gives me this however

 

Warning: array_intersect() [function.array-intersect]: Argument #2 is not an array in /home//public_html/main/tester.php on line 29

Array ( [topic_id] => 33 )

 

why isn't my second "array"($ult) not an array?

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.