How to compare the coma separate(,) values in two cols of different table?

hi guys!
currently i am really in bad situation i m trying to compare two column values from different tables.
but the thing is theses are coma separated values like (1,2,3,4,5…)

ohky now come to the point

i have two tables table one and table two
1

inside of table one i have these columns

Untitled

and in table two

Untitled

Now what i want is compare the val2 column of table two with all the values val2 of table two

for example:
in table two where val1=1 would be compare with val2 all columns

result would be like:
if 74,75 value of table two is compare with value of table one 74,75
then common answer will be retuen
1 of val1 column of table one and display 74,75 are common

again if 74,75 value of table two is compare with value of table one 73,74
then common answer will be retuen
2 of val1 column of table one and display only 74 is common

here is the code which i use to compare

     $a = "74,75";
     $b = "74,75";

     $a_arr = explode(",", $a);
     $b_arr = explode(",", $b);

	$values_in_both = array_intersect($a_arr, $b_arr);

	foreach($values_in_both as $rrr)
		{
			echo $rrr;
		}


output: 74
        75

can any one know the solution? please reply i relay thankful if you know the code in php.
i know experts are here…

The code is really painful to do.
My recommendations are stackoverflow, they are real brain stormers.

1 Like

Already posted sir. No helpful replay i got

1 Like

hi ckhawand!
finally i made it my own and its work well according to my need this is the answer of this question that why i m posting solution here maybe some one like me needs in future…
at last your are great allways help other thankyou.

     $query=mysqli_query($db,"select * from two where val1=1");
              while($rows = mysqli_fetch_array($query))
             {
                               $val1=$rows['val1'];
                              $val2=$rows['val2'];

                            $str = "$val2";
                           $ggg=explode(",",$str);
                            foreach( $ggg as $val ){


                                $array=$val;
                                $vm[]=$array;

               }

                                          $text = implode("|", $vm);
                                     $new_query=mysqli_query($db,"SELECT * from one where CONCAT(',', `val2`, ',') REGEXP ',($text),';");
                        while($row = mysqli_fetch_array($new_query))
                   {
                            echo $row['val1'].'</br>';
                           echo $row['val2'].'</br>';
                         }

                }
1 Like

Thank you for sharing your hardwork! :slight_smile:

1 Like