<?php
	session_start();
	if($_SESSION['adm'])
	{
		$userid= $_SESSION['adm'];
	}
	else
	{
		header('location:../login.php');
	}
	
	include'connection.php';
	include'time.php';
?>
<html>
    <body>
        <form method="POST">
            <input type="submit" name="SUBMIT2" value="ALL LAPU">
        </form></br>
        <form method="POST">
            <input type='text' name='searchName'>
            <select name='sellerName'>
                <option>--SELECT SELLER--</option>
                <?php
                    $quSeller="SELECT * FROM Seller ORDER BY Name ASC";
                    $reSeller=mysqli_query($con,$quSeller);
                    while($dataSeller=mysqli_fetch_array($reSeller))
                    {
                        echo "<option>".$dataSeller['Name']."</option>";
                    }
                    
                ?>
                <option>
            </select>
            <select name="update">
                <option>UPDATE</option>
                <option>NOTUPDATE</option>
            </select>
            <input type="submit" name="SUBMIT">
        </form>
    </body>
</html>
<?php
    if(isset($_POST['SUBMIT']))
    {
        $searchName= $_POST['searchName'];
        $sellerName= $_POST['sellerName'];
        $update= $_POST['update'];
        $sl1=0;
        $qu1="SELECT * FROM myapi WHERE Seller='$searchName' ORDER BY Seller ASC";
        $re1=mysqli_query($con,$qu1);
        while($data1=mysqli_fetch_array($re1))
        {
            $sl1=$sl1+1;
            echo $sl1." - ".$data1['Seller']." - ".$data1['LapuNumber']."</br>";
            $lapuId = $data1['Id']."</br>";
        
            if($update=="UPDATE")
            {
                mysqli_query($con,"UPDATE myapi SET Seller='$sellerName' WHERE Id='$lapuId'");
                $msg ="UPDATED";
            }
            else
            {
                
                $msg ="NOT UPDATED";
            }
        }
        echo "<br><br><h3>".$msg."</h3><br><br>";
        $sl2=0;
        $qu2="SELECT * FROM myapi WHERE Seller='$sellerName'";
        $re2=mysqli_query($con,$qu2);
        while($data2=mysqli_fetch_array($re2))
        {
            $sl2=$sl2+1;
            echo $sl2." - ".$data2['Seller']." - ".$data2['LapuNumber']."</br>";
        }

    }
    if(isset($_POST['SUBMIT2']))
    {
        
        $sl1=0;
        $qu1="SELECT * FROM myapi ORDER BY Seller ASC";
        $re1=mysqli_query($con,$qu1);
        while($data1=mysqli_fetch_array($re1))
        {
            $sl1=$sl1+1;
            echo $sl1." - ".$data1['Seller']." - ".$data1['LapuNumber']."</br>";
        }
    }

?>