controller
Código
case 'search': $main = 0; $limit = 3; $page = $_POST['page']; $main = ($page - 1) * $limit; } $id = $_POST['id']; $search = new product(); $__result= $search->searchProduct($id); $final_result = $search->searchProduct($id,$main,$limit); break; case 'update': $id = $_POST['id']; $editCode = $_POST['editCode']; $editProduct = $_POST['editProduct']; $editPrice = $_POST['editPrice']; $editStock = $_POST['editStock']; $update = new product(); if($update->update($id,$editCode,$editProduct,$editPrice,$editStock)){ $stock = $update->getProductStock($id); if ($stock > 20) { notification::removeNotifications($id); } echo 'sucess'; }else{ echo "No se Actualizo los datos"; } break;
model
Código
function update($id,$editCode,$editProduct,$editPrice,$editStock){ $sql="UPDATE product SET code = '{$editCode}',product='{$editProduct}',purchase_price={$editPrice},stock={$editStock} WHERE idproduct={$id}"; //echo $sql; if($this->conexion->conexion->query($sql)){ return true; } else{ return false; } $this->conexion->cerrar(); }
Código
function searchProduct($id,$main=false,$limit=false){ if($main !== false && $limit !== false){ $sql="SELECT md5(idproduct) AS id,code,product,purchase_price,stock,product.status FROM product WHERE code like '%".$id."%' or product like '%".$id."%' ORDER BY id ASC LIMIT $main,$limit"; }else{ $sql="SELECT md5(idproduct) AS id,code,product,purchase_price,stock,product.status FROM product WHERE code like '%".$id."%' or product like '%".$id."%' ORDER BY id"; } $this->conexion->conexion->set_charset('utf8'); $result=$this->conexion->conexion->query($sql); while($record = $result->fetch_array(MYSQLI_NUM)){ $array[] = $record; } return $array; echo $result; $this->conexion->cerrar(); }