0

I've been working on this code for some times and I want a better way than I've written. I want to get any of the column where they id are 1 and compare them one by one with table2, and echo those which are the same:

enter image description here

$user_id="1";
    $job_list = mysql_query("SELECT * FROM   tbl_job WHERE user_id=$user_id");

    while ($row2 = mysql_fetch_row($job_list)) { 
$a[]=$row2[0]; 
$b[]=$row2[1]; 
$c[]=$row2[2];
}
// echo $a[0] => john
// echo $a[1] => sara

and this code compares them one by one and create array:

$job_list3 = mysql_query("SELECT * FROM   tbl_job_2 WHERE 
    name=    '$a[0]' AND
    job=     '$b[0]' AND
    location='$c[0]' ");

    while ($row3 = mysql_fetch_row($job_want_list3)) { 
$aa[]=$row3[0]; 
$bb[]=$row3[1]; 
$cc[]=$row3[2];
}

but I think this is the wrong way! Is there a better way? Thanks

Edit:

For better understanding: I get the output of the second code and put it in the array. But that's the wrong way, because I have to print a lot of variables. I think in some way I shold use WHILE command.

friedemann_bach
  • 1,418
  • 14
  • 29
behzad
  • 17
  • 3
  • `mysql_*` is deprecated as of [tag:php-5.5]. So instead use `mysqli_*` or `PDO`. [Why shouldn't I use mysql_* functions in PHP?](https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php/14110189#14110189) – mega6382 Oct 19 '17 at 09:19
  • I changed and corrected.. is tow table – behzad Oct 19 '17 at 09:28
  • Sounds like you need a [join](https://en.wikipedia.org/wiki/Join_(SQL)) e.g. `select * from tbl_job_1 tj1 JOIN tbl_job_2 tj2 ON tj1.id = tj2.id` – IanB Oct 19 '17 at 09:29

0 Answers0