1
mysql을 사용하는 작업 업데이트 쿼리가 있지만 현재 페이지를로드하는 속도가 매우 느립니다. 내 쿼리를 더 빨리 업데이트 할 수있는 방법이 있습니까?PHP/MYSQL- 루핑 내부 업데이트. 느린로드 페이지
여기에 내 코드
<?php
$sql = "select ite_desc,ecr_desc, pric_cash, t.itemcode as itemcode ,sum(t.qty) as qty
from (
select ite_desc,ecr_desc, pric_cash, itemcode,qty from barcode as bc inner JOIN allinvty3 as ait on bc.itemcode = ait.in_code
union all
select ite_desc,ecr_desc, pric_cash, itemcode,qty from branchtobranch_tb as bb inner JOIN allinvty3 as ait on bb.itemcode = ait.in_code
union all
select ite_desc,ecr_desc, pric_cash, itemcode,qty from adjustment_tb as adt inner JOIN allinvty3 as ait1 on adt.itemcode = ait1.in_code where adt.status='APPROVED'
union all
select ite_desc,ecr_desc, pric_cash, itemcode,qty from stockreturn_tb as sb inner JOIN allinvty3 as ait on sb.itemcode = ait.in_code
union all
select ite_desc,ecr_desc, pric_cash, itemcode,qty from notinclude_tb as nt inner JOIN allinvty3 as ait on nt.itemcode = ait.in_code where nt.status='COMPLETE'
union all
select ite_desc,ecr_desc, pric_cash, itemcode,qty from purchase_tb as pt inner JOIN allinvty3 as ait on pt.itemcode = ait.in_code
union all
select ite_desc,ecr_desc, pric_cash, itemcode,(qty * -1) from soldout_pd as slp inner JOIN allinvty3 as ait2 on slp.itemcode = ait2.in_code) as t
group by itemcode order by ecr_desc ASC ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "
</tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
$total =$row['qty'];
$itemcode=$row['itemcode'];
$sql1="UPDATE allinvty3 set sa_onhand = '".$total."' where in_code ='".$itemcode."'" ;
$conn->query($sql1);
}echo " </table>";}
?>
의 단일 쿼리로이 작업을 수행 할 수 있습니다
경고 ** ** mysql을 사용할 때 [매개 변수가있는 쿼리] (http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)와 ['bind_param' ] (http://php.net/manual/en/mysqli-stmt.bind-param.php)를 사용하여 쿼리에 사용자 데이터를 추가하십시오. ** 심각한 [SQL injection bug] (http://bobby-tables.com/)를 만들었 기 때문에 문자열 보간이나 연결을 사용하여 **이를 수행하지 마십시오. **'$ _POST' 또는'$ _GET' 데이터를 쿼리에 직접 입력하지 마십시오. 실수로 누군가를 악용하려고 시도하면 매우 위험 할 수 있습니다. – tadman