Please help me.I want my codes to check existence data in database. In my system, i have L1 till L14 with Location A and B. I want my codes to check in the database if the data possible to insert or not. Below is the example of my table. Table shows the status of location and line if I install any data into it. Then, I got problem at table A,when I insert data into my system page, the data will skip the other line and jump to insert data into the last line(which is L14). I cannot detect whether my looping or my condition are wrong. Help me, im still student and new to this.Thank you ^^
Table
ID Location Line Status
1 A L1 Installed
2 : :
A
Line SN Status
L1 a12 :
L2 a33 :
L3 : :
:
L14
This is my php codes, there are two codes, one is for function,and one more is for installation
function.php
function getLocation($model){
$line='$line';
$location='$location';
for($i=1; $i<=14; $i++)
{
if($find=true){
$location="A";
$line="L".$i;
$result=mysqli_query($GLOBALS['conn'], "SELECT * FROM Table WHERE location='$location' AND line='$line'");
if(!$result&&!$find){
$location="A";
$line='$line';
$find=false;
break;
}
}
}
if(!$find){
for($i=1; $i<=14; $i++)
{
$line="L".$i;
$location="B";
$result=mysqli_query($GLOBALS['conn'], "SELECT * FROM Table WHERE location='B' AND line='$line'");
if(!$result&&!$find){
$location='B';
$line='$line';
$find=true;
break;
}
}
}
$loc=array($location,$line);
return $loc; }
And, this is my second codes which to call above function.php
if (isset($_POST["savebtn"])){
$SN=$_POST["SN"];
$ status=$_POST["status"];
$action=$_POST["action"];
$remark="Adding new data";
$loc=array();
if(AddData($SN, $ status)){
$ID=getPumpID($SN);
addRecord($ID, $SN, $ status , 'Add Data');
if($action=="install")
{
$ID=getID($SN);
$loc=getLocation($model);//model-database contain location
$location= $loc[0];
$line= $loc[1];
//$location = $loc;
//$line = $loc;
if(deployed($ID, $location, $line)){
}
}
}
Aucun commentaire:
Enregistrer un commentaire