vendredi 16 juin 2017

PHP - in_array, loops, and if statements

I have a database for scheduling field techs. Each field tech has his own unique login id that can see only his own specific jobs. I have recently added the function to add multiple techs to a single ticket. I am currently running the follow loop. Each tech can currently see each job he is assigned on alone. When I start to assign multiple tech is where it gets tricky. Let's say I have 3 techs total: Mickey, Dustin, and Michael.

If I assign 1 job as a multi tech job for Michael and Dustin it appears fine in both techs lists. If I then assign another job for Mickey and Dustin. The previous job I assigned as a multi tech for Dustin disappears from his list but still shows on Michaels.

I am assuming something is getting caught up in the loop but I am having trouble figuring it out. Im a noob. Need Help.

$gettechresult = mysql_query("SELECT tech_id2, tech_id FROM jobs WHERE ((status = '2')) ORDER by $listsort;",$link);
    while ($p_row =mysql_fetch_array ($gettechresult) ) {
        $tech_id2 = $p_row[tech_id2];
        $tech_id = $p_row[tech_id];
        $fids = explode(",",$tech_id2);
        $fids2 = explode(",",$tech_id);

        if (in_array($l_tech_id, $fids)) {$techteam = 'TRUE';}
             else {$techteam = 'False';}

    /// Used to make sure the query is not returning False Values        
    echo "$techteam,";

        if ($grp_all == "1") { $jobresult = mysql_query("SELECT * FROM jobs WHERE ((status = '2')) ORDER by $listsort;",$link); }

        elseif ((in_array($l_tech_id, $fids))) { $jobresult = mysql_query("SELECT * FROM jobs WHERE ((tech_id2 ='$l_tech_id' AND status = '2' || tech_id2 IN ('".$fids."') AND status = '2')) ORDER by $listsort;",$link); }
                     }

Aucun commentaire:

Enregistrer un commentaire