如何为表声明多个where条件

hi guy's i have a question. how to declare a multiple where clause condition inside one php only. i have try to make my project has a minimum of a php file. i want to make my where clause inside one php file only.

this is the problem i mean. i want to put my code into one php file or inside one <?php ?>. the php code like this

<?php
include("../../Connections/koneksi.php");

$date1= $_POST['date1'];
// Data for Titik1
$sql = "SELECT * FROM termocouple where tanggal='$date1' AND silo='Silo 1'";
$query = mysqli_query($db,$sql);
$rows = array();

while($tmp= mysqli_fetch_assoc($query)) {
    $rows[] = $tmp;
}

echo json_encode($rows);
mysqli_close($db);
?> 

on the code above the query has select table termocouple and the filter of where condition is tanggal and silo. now the problem is i have 12 php file like that. and the different of every php is from the selecting silo, i put Silo 1,Silo 2,Silo 3, ....Silo 12.

please someone help me with this. i want to make it simple in one php file. im really appreciated when you give me an example

</div>

I am assuming these 12 PHPs are called in diff scenarios. Why dont you pass some param from client side so that the PHP knows which scenario to execute.

$date1= $_POST['date1'];
$silo= $_POST['silo'];//This could be 'Silo 1 OR 'Silo 2' etc.
// Data for Titik1
$sql = "SELECT * FROM termocouple where tanggal='$date1' AND silo='$silo'";
$query = mysqli_query($db,$sql);

In order to minimize your code, if you are using the same query or code more than one time in the same project, it is more recommended to create a function, that you will call anytime you need to execute the code.

So here, since you are using the same query 12 times, you will have to create a function that executes this query, and then call this function every time you want to execute the query.

The function takes parameters, so you will have to give the function the database connection parameter $db in order to connect to the database since you are using this connection inside the function, and then you have to add the values of the where clause to the parameters also.

So your function here will take the database connection $db, $date1 fetched from $_POST, and $silo fetched from $_POST

At the end of the function, you can return any value you wish to return, so in your case, you will have to return the $rows array fetched from the query

Create a common php fileand create a function in it. Lets say the file name is libraries.php

in this file write the following code:

<?php
    function getRows($db, $date, $silo) {
        $sql = "SELECT * FROM termocouple where tanggal='$date' AND silo='$silo'";
        $query = mysqli_query($db, $sql);
        $rows = array();

        while($tmp= mysqli_fetch_assoc($query)) {
            $rows[] = $tmp;
        }

        return json_encode($rows);
    }
?>

And in each of the files where you are calling the query you will remove the php code and replace it with the following:

<?php
include("../../Connections/koneksi.php");
include("{path-to-file}/libraries.php");

$date1= $_POST['date1'];
$silo = $_POST['silo'];

$rows = getRows($db, $date1, $silo) ;
?>