php - Find a value that could appear multiple times but only use other value once -


title maybe bit confusing because didn't know how explain myself...

the problem have have comments table in stored instance comment about, comment , user commented, i'm trying collect instances have been commented user. if instance has been commented twice select instance once.

currently have code returning instances

$test = @mysql_query("select * comments user_id = '$idd'"); while($result = mysql_fetch_array($test)) {     $id = $result['instance_id'];     $gender = $result['gender'];     $name = $result['name'];      $test2 = @mysql_query("select * media_link instance_id = $id");     $result2 = mysql_fetch_array($test2);      $media = $result2['media_id'];      $test3 = @mysql_query("select * comments instance_id = $id");     $result3 = mysql_fetch_array($test3);     $comments = $result3['comments']; 

the attributes arranged in table , echoed out within while loop.

sounds job distinct keyword (info here). weren't super clear on schema looks like, working provided:

$test = @mysql_query("select distinct instance_id comments user_id = '$idd'"); 

this perform selection, ignore redundant rows in result, you'll each thread/instance user commented in, each thread appear once.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -