php dynamic search build query






<?php
 $hostName = "localhost";
 $userName = "root";
 $password = "";
 $dbName = "pobpaper";
 $conn= new mysqli($hostName,$userName,$password,$dbName);
 if(!$conn){
    echo "DB is not connected";
 }

 $jt = $_GET["jt"];
 $jc = $_GET["jc"];

 $myArr = [];

 if($jt != NULL){
    $new = explode(" ", $jt);
    echo $new[0];
    $c = count($new);
    echo $c;
    if($c == 1){
        if($new[0] == 'remote'){
            array_push($myArr,(object)["st"=> 'jobtype','jtid'=>'1']);
        }
        else{
            array_push($myArr,(object)["st"=> 'jobtype','jtid'=>'2']);

        }

    }
    else if($c == 2){
        if($new[0] == 'remote'){
            echo 'came';
            array_push($myArr,(object)["st"=> 'jobtype','jtid'=>'1,2']);
        }
        else{
            array_push($myArr,(object)["st"=> 'jobtype','jtid'=>'2,1']);
        }
    }
    echo 'array length';
    echo count($myArr);
 }
 if($jc != NULL){
    $new = explode(" ", $jc);
    echo $new[0];
    $c = count($new);
    echo $c;
    if($c == 1){
        if($new[0] == 'nodejs'){
            array_push($myArr,(object)["st"=> 'jobcategory','jtid'=>'1']);
        }
        else{
            array_push($myArr,(object)["st"=> 'jobcategory','jtid'=>'2']);

        }

    }
    else if($c == 2){
        if($new[0] == 'nodejs'){
            echo 'came';
            array_push($myArr,(object)["st"=> 'jobcategory','jtid'=>'1,2']);
        }
        else {
            array_push($myArr,(object)["st"=> 'jobcategory','jtid'=>'2,1']);

        }
    }
 }

 echo"array 12" ;
 var_dump($myArr[0]-> st);
 if(count($myArr) == 1){
     $firs = $myArr[0]-> st;
     $sec = $myArr[0]-> jtid;


        $query = "SELECT * FROM sometable WHERE `$firs` IN ($sec)";

 
     echo $query;
     $result = mysqli_query($conn,$query);
     while($row = mysqli_fetch_assoc($result)){
        echo " ". $row['sno'] ;
    }
 }
 else if(count($myArr) == 2){
    $firs = $myArr[0]-> st;
    $sec = $myArr[0]-> jtid;
    $firs2 = $myArr[1]-> st;
    $sec2 = $myArr[1]-> jtid;

     $query = "SELECT * FROM sometable WHERE `$firs` IN ($sec) AND `$firs2` IN ($sec2)";

 
    echo $query;
    $result = mysqli_query($conn,$query);
    while($row = mysqli_fetch_assoc($result)){
       echo " ". $row['name'] ;
   }

 }
//  $subname = $_GET["subname"];

?>

Comments

All time Best Post

Write a program that declares a class named Person. It should have instance variables to record name, age and salary. Use new operator to create a Person object. Set and display its instance variables.

IMAGE CRUD OPERATION USING EXPRESS MONGOOSE MULTER

connect websocket to binance api and store t he true value in the db

CRUD APP WITH SORT IN NODE EXPRESS AND MONGODB

express session login system using node express mongodb

how to delete image from the folder directly from a Request (MULTER)

calculate rsi

java program for 1 to 10 print using while loop

How to fetch last one minute volume of BTC in CCXT Nodejs.