PHP MySQLi Match two table ID then redirects

I want to match the ID of two tables then if the ID matched redirect it to specific page.

SELECT user_skill.user_id AS id_one, job_seeker.user_id AS id_two
FROM user_skill 
INNER JOIN job_seeker ON (user_skill.user_id = job_seeker.user_id)

using this condition below

if(mysqli_num_rows($result) > 0) {
    while($fetch = mysqli_fetch_assoc($result)) {

        if($fetch['id_one'] === $fetch['id_two']) {

            header('location: userhome.php');

        }
        else {

            header('location: userskill.php');

        }

     }

}

Any suggestions would be helpful. Thanks!!

1 answer

  • answered 2018-01-19 05:41 Mazhar Hussain

    SELECT user_skill.user_id AS id_one, job_seeker.user_id AS id_two
    FROM user_skill 
    INNER JOIN job_seeker ON (user_skill.user_id = job_seeker.user_id)
    

    using this condition below

    if(mysqli_num_rows($result) > 0) {
        while($fetch = mysqli_fetch_assoc($result)) {
    $variable=array($fetch['id_one']=>$fetch['id_two']);
     foreach($variable as $x=$value)
    

    { if($x === $value) {

                header('location: userhome.php');
    
            }
            else {
    
                header('location: userskill.php');
    
            }
    }
         }
    
    }