Greetings! I'm in my advance view, making a conditional query.
This is what I tried so far.
Code:
public static function advanceView($labs,$pcs=null)
    {
       
        if ($pcs == !null)
        {
            $pc  =  "AND lab.pclab.pclab_name = :pc";
            $param = 1;
        }
        else
        {
            $pc= "";
            $param = 0;
        }
       
        try{
              $sql = "  SELECT 
                            device.sn.sn_number AS sn,
                            device.sn.sn_id AS sn_id
                        FROM lab.labname
                        INNER JOIN lab.pclab ON lab.labname.lab_id = lab.pclab.lab_id
                        AND device.names.dlist_id = device.list.dlist_id
                        WHERE device.sn.sn_delstat IS NULL
                        AND lab.labname.lab_id = :lab
                        $pc                 
                                              
                        ";
                $q = connection::$db->prepare($sql);
               
              
                if ($param = 1)
                {
                        $q -> bindParam(':pc',$pcs,PDO::PARAM_STR);
                        $q -> bindParam(':lab',$labs,PDO::PARAM_INT);
                }
                else 
                {
                        $q -> bindParam(':lab',$labs,PDO::PARAM_INT);
                }
                
                $q -> execute();
It works well if I will not leave the variable $labs and $pcs empty. But if I want to select only the $labs, there is an error like
Code:
rror!:SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
any idea?