|
|
|
insert ข้อมูลทีละมากๆ แล้วนานมากครับเวลาขึ้น host จริง |
|
|
|
|
|
|
|
Insert แบบไหนครับ ใช้ loop หรือเปล่าครับ ปกติการ Insert มักจะทำงานแป๊บเดียว
|
|
|
|
|
Date :
2013-03-31 16:55:48 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
code ที่ผมทำงานอ่ะครับ
Code (PHP)
if($check == "true")
{
$ccurrent = "true";
date_default_timezone_set("Asia/Bangkok");
$sql = "select Gt_id from gettake order by Gt_id desc limit 1";
$rs = mysql_query($sql);
$num = mysql_num_rows($rs);
if($num != 0)
{
while($row = mysql_fetch_object($rs))
$id = $row->Gt_id + 1 ;
}
else
$id = 1;
$sql = "insert into gettake (Gt_id,Tm_id,Emp_id,Gt_date,Gt_status) values ('".$id."','".$idtake."','".$iduser."','".date("Y-m-d H:i:s")."','0')";
mysql_query($sql);
$sql = "select Gt_id from gettake order by Gt_id DESC limit 1";
$rs = mysql_query($sql);
while($row = mysql_fetch_object($rs))
$idgt = $row->Gt_id;
for($i = 0 ; $i < $count;$i++)
{
$sql = "insert into detail_gettake (Gt_id,Imm_id,D_gt_amount) values ('".$idgt."','".$idimm[$i]."','".$amount[$i]."')";
mysql_query($sql);
$sql = "select Imp_amount from inventory_materials_parts where Imp_id='".$idimm[$i]."' and Branch_id='".$idbranch."'";
$rs = mysql_query($sql);
while($row = mysql_fetch_object($rs))
{
$total = $amount[$i] + $row->Imp_amount;
$sql1 = "update inventory_materials_parts set Imp_amount='".$total."' where Imp_id='".$idimm[$i]."' and Branch_id='".$idbranch."'";
mysql_query($sql1);
}
}
$sql = "select dtm.Imm_id,dtm.D_tm_amount from takematerials tm , detail_takematerials dtm where tm.Tm_id = dtm.Tm_id and tm.Tm_id='".$idtake."' order by Imm_id";
$rs = mysql_query($sql);
$ccurrent = "true";
$index=0;
while($row = mysql_fetch_object($rs))
{
$takeimmid[] = $row->Imm_id;
$takeamount[] = $row->D_tm_amount;
$index++;
}
$sql = "select dgt.Imm_id , sum(dgt.D_gt_amount) as sumamount from gettake gt , detail_gettake dgt where gt.Gt_id = dgt.Gt_id and gt.Tm_id='".$idtake."' group by dgt.Imm_id order by dgt.Imm_id";
$rs = mysql_query($sql);
while($row = mysql_fetch_object($rs))
{
$getimmid[] = $row->Imm_id;
$getamount[] = $row->sumamount;
}
for($j=0;$j<$index;$j++)
{
if($takeimmid[$j] == $getimmid[$j])
{
if($getamount[$j] != $takeamount[$j])
{
$ccurrent = "false";
break;
}
}
else
{
$ccurrent = "false";
}
}
/*----------------------- เช็คว่า รับครบ แล้วหรือยัง ---------------------------------*/
if($ccurrent == "true")
{
$sql = "update gettake set Gt_status='1' where Gt_id='".$idgt."'";
mysql_query($sql);
$sql = "update takematerials set Tm_status='1' where Tm_id='".$idtake."'";
mysql_query($sql);
}
else
{
$sql = "update gettake set Gt_status='2' where Gt_id='".$idgt."'";
mysql_query($sql);
$sql = "update takematerials set Tm_status='2' where Tm_id='".$idtake."'";
mysql_query($sql);
}
echo "<script>window.location.reload()</script>";
}
|
|
|
|
|
Date :
2013-03-31 18:39:50 |
By :
kokiflam |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เข้าใจว่าช้าตรง SELECT หรือเปล่าครับ ลอง echo เอาค่า SQL ไปรันใน phpMyAdmin ดูครับ
|
|
|
|
|
Date :
2013-03-31 19:30:56 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$sql เปลี่ยนตัวแปรอย่าให้ซ้ำกัน
|
|
|
|
|
Date :
2013-04-02 16:34:12 |
By :
teez1232002 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|