Mysql Select Query Success on Mysql Client But Failed through PHP -


i have query run fine through heidisql if through php, fails without error report.

here code

php

    $sql = "select `pob`.`id` , `pob`.`po_qty` , ifnull(`mrb`.`rcv_qty`,0) `rcv_qty` , ( `pob`.`po_qty` - ifnull( sum( `mrb`.`rcv_qty` ), 0 )) balance `mpo_body` `pob` left join `mrcv_body` `mrb` on `pob`.`id` = `mrb`.`po_id` `pob`.`id`='$id' group `pob`.`id`";      $result = $mysqli->query($sql);     if($result->num_rows>0){         $row = $result -> fetch_assoc();         if($row['balance']>0){             $sql = "update `mpo_body` set close='y' `id`='$id'";             echo $mysqli->query($sql);         }else{             echo "failed here";         }     }else{         echo "failed @ here";     } 

what causing problem here?

update

this structure of data in mpo_body

drop table if exists `mpo_body`;  create table `mpo_body` (   `id` int(10) unsigned not null auto_increment,   `po_no` varchar(30) not null default '',   `item_no` char(3) not null default '',   `matcode` varchar(25) not null default '',   `po_qty` decimal(16,2) not null default '0.00',   `unit_price` decimal(20,2) not null default '0.00',   `etd_date` date not null default '0001-01-01',   `po_bal` double not null default '0',   `ref_no` varchar(255) not null default '',   `dept_no` varchar(25) not null default '',   `uom` varchar(10) not null default '',   `factor` int(11) not null default '1',   `rev_no` varchar(5) not null default '',   `cancel` char(1) not null default 'n',   `del_note` varchar(100) not null default '',   `closed` char(1) not null default 'n',   `upt_time` time not null,   `prid` int(11) not null,   `remark` varchar(200) not null default '',   primary key (`id`),   key `matcode` (`matcode`) ) engine=myisam default charset=latin1;  lock tables `mpo_body` write; /*!40000 alter table `mpo_body` disable keys */;  insert `mpo_body` (`id`, `po_no`, `item_no`, `matcode`, `po_qty`, `unit_price`, `etd_date`, `po_bal`, `ref_no`, `dept_no`, `uom`, `factor`, `rev_no`, `cancel`, `del_note`, `closed`, `upt_time`, `prid`, `remark`) values     (1,'p05-000001','002','30001352',1.00,1.00,'2016-05-28',1,'','purchasing','pcs',1,'','n','','n','00:00:00',21,''),  (2,'p05-000001','001','30001352',1.00,1.00,'2016-05-28',1,'','ppmc','pcs',1,'','n','','n','00:00:00',4,'');  /*!40000 alter table `mpo_body` enable keys */; unlock tables; 

you must use while bellow:

$sql = "select `pob`.`id` , `pob`.`po_qty` , ifnull(`mrb`.`rcv_qty`,0) `rcv_qty` , ( `pob`.`po_qty` - ifnull( sum( `mrb`.`rcv_qty` ), 0 )) balance `mpo_body` `pob` left join `mrcv_body` `mrb` on `pob`.`id` = `mrb`.`po_id` `pob`.`id`='$id' group `pob`.`id`";      $result = $mysqli->query($sql);     if($result->num_rows>0){          while($row = $result->fetch_assoc()) {              if($row['balance']>0){                 $sql = "update `mpo_body` set close='y' `id`='$id'";                 echo $mysqli->query($sql);             }else{                 echo "failed here";             }         }      }else{         echo "failed @ here";     } 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -