PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/1851063119_DANGVANXIM/php/admin_frm_sanpham.php

https://gitlab.com/Johnxim/ptdapm
PHP | 147 lines | 126 code | 21 blank | 0 comment | 4 complexity | b139b8241892d928ba365c2febefc9e2 MD5 | raw file
  1. <?php
  2. require_once("server.php");
  3. $event=$_GET["event"];
  4. switch ($event) {
  5. case "getspdetail":
  6. $mang=array();
  7. $masp=$_GET["masp"];
  8. $sql=mysqli_query($conn,"SELECT Product_ID,Product_Name,Actual_Price,Quoted_Price,Category_ID,Supplier_ID,img FROM products WHERE Product_ID = '".$masp."'");
  9. while($rows=mysqli_fetch_array($sql)){
  10. $id=$rows['Product_ID'];//Không lặp ID theo từng trang
  11. $usertemp['Product_ID']=$rows['Product_ID'];
  12. $usertemp['Product_Name']=$rows['Product_Name'];
  13. $usertemp['Actual_Price']=$rows['Actual_Price'];
  14. $usertemp['Quoted_Price']=$rows['Quoted_Price'];
  15. $usertemp['Category_ID']=$rows['Category_ID'];
  16. $usertemp['Supplier_ID']=$rows['Supplier_ID'];
  17. $usertemp['img']=$rows['img'];
  18. $mang[$id]=$usertemp;
  19. }
  20. $jsonData['items'] =$mang;
  21. echo json_encode($jsonData);
  22. mysqli_close($conn);
  23. break;
  24. case 'timkiem':
  25. $masp=$_GET["masp"];
  26. $mang=array();
  27. $sql=mysqli_query($conn,"SELECT * FROM `products` WHERE Product_ID='".$masp."'");
  28. while($rows=mysqli_fetch_array($sql)){
  29. $id=$rows['Product_ID'];//Không lặp ID theo từng trang
  30. $usertemp['Product_ID']=$rows['Product_ID'];
  31. $usertemp['Product_Name']=$rows['Product_Name'];
  32. $usertemp['Actual_Price']=$rows['Actual_Price'];
  33. $usertemp['Quoted_Price']=$rows['Quoted_Price'];
  34. $usertemp['Category_ID']=$rows['Category_ID'];
  35. $usertemp['Supplier_ID']=$rows['Supplier_ID'];
  36. $usertemp['img']=$rows['img'];
  37. $mang[$id]=$usertemp;
  38. }
  39. $jsonData['items'] =$mang;
  40. echo json_encode($jsonData);
  41. mysqli_close($conn);
  42. break;
  43. case "insertsp":
  44. $masp=$_GET["masp"];
  45. $tensp=$_GET["tensp"];
  46. $giathuc=$_GET["giathuc"];
  47. $gianiemyet=$_GET["gianiemyet"];
  48. $matl=$_GET["matl"];
  49. $mancc=$_GET["mancc"];
  50. $anh=$_GET["anh"];
  51. $sql="INSERT INTO `products` (Product_ID, Product_Name, Actual_Price, Quoted_Price, Category_ID, Supplier_ID, img) VALUES('".$masp."','".$tensp."','".$giathuc."','".$gianiemyet."','".$matl."','".$mancc."','".$anh."')";
  52. if (mysqli_query($conn, $sql))//cấu trúc: mysqli_query(connection, query, resultmode)
  53. {
  54. $res[$event] = 1;
  55. }
  56. else
  57. {
  58. $res[$event] = 0;
  59. }
  60. echo json_encode($res);//Cấu trúc: json_encode(value, options, depth), Ở đây giống như đang mã hóa thì phải
  61. mysqli_close($conn);
  62. break;
  63. case "getspadmin":
  64. $mang=array();
  65. $record=$_GET['record'];//biến dùng để phân trang
  66. $page=$_GET['page'];
  67. $vt=$page*$record;
  68. $limit='limit '.$vt.' , '.$record;//Lấy $record dòng, tính từ thứ tự thứ $vt của kết tập kết quả
  69. $sql=mysqli_query($conn,"select Product_ID,Product_Name,Actual_Price,Quoted_Price,Category_ID,Supplier_ID,img from products ".$limit);
  70. while($rows=mysqli_fetch_array($sql)){
  71. $id=$rows['Product_ID'];//Không lặp ID theo từng trang
  72. $usertemp['Product_ID']=$rows['Product_ID'];
  73. $usertemp['Product_Name']=$rows['Product_Name'];
  74. $usertemp['Actual_Price']=$rows['Actual_Price'];
  75. $usertemp['Quoted_Price']=$rows['Quoted_Price'];
  76. $usertemp['Category_ID']=$rows['Category_ID'];
  77. $usertemp['Supplier_ID']=$rows['Supplier_ID'];
  78. $usertemp['img']=$rows['img'];
  79. $mang[$id]=$usertemp;
  80. }
  81. $rs=mysqli_query($conn,"select COUNT(*) as 'total' from products");//Duyệt số thứ tự
  82. $row=mysqli_fetch_array($rs);//Cấu trúc mysqli_fetch_array(result,resulttype)
  83. $jsonData['total'] =(int)$row['total'];
  84. $jsonData['totalpage'] =ceil($row['total']/$record);
  85. $jsonData['page'] =(int)$page;
  86. $jsonData['items'] =$mang;
  87. echo json_encode($jsonData);
  88. mysqli_close($conn);
  89. break;
  90. case 'updatesp':
  91. $masp=$_GET["masp"];
  92. $tensp=$_GET["tensp"];
  93. $giathuc=$_GET["giathuc"];
  94. $gianiemyet=$_GET["gianiemyet"];
  95. $matl=$_GET["matl"];
  96. $mancc=$_GET["mancc"];
  97. $anh=$_GET["anh"];
  98. $sql="UPDATE `products` SET Product_Name='".$tensp."', Actual_Price='".$giathuc."', Quoted_Price='".$gianiemyet."', Category_ID='".$matl."', Supplier_ID='".$mancc."', img='".$anh."' WHERE Product_ID='".$masp."'";
  99. if (mysqli_query($conn, $sql))//cấu trúc: mysqli_query(connection, query, resultmode)
  100. {
  101. $res[$event] = 1;
  102. }
  103. else
  104. {
  105. $res[$event] = 0;
  106. }
  107. echo json_encode($res);//Cấu trúc: json_encode(value, options, depth), Ở đây giống như đang mã hóa thì phải
  108. mysqli_close($conn);
  109. break;
  110. case "deletesp":
  111. $masp=$_GET["masp"];
  112. $sql="DELETE FROM `products` WHERE Product_ID='".$masp."'";
  113. mysqli_query($conn, $sql);
  114. if(mysqli_affected_rows($conn)>0){
  115. $res[$event] = 1;
  116. }
  117. else{
  118. $res[$event] = 0;
  119. }
  120. echo json_encode($res);
  121. mysqli_close($conn);
  122. break;
  123. default:
  124. break;
  125. }
  126. ?>