php - Mysql query error when using ">" operator -
i want output mysql database json. there problem in code. problem if put 0,1,2,3 or 4 here tbl_stock.qty> ? ,no output given. if put 5 or higher number 5 gives me output.
my php code
<?php require_once 'include/configg.php'; header('content-type: application/json'); $con = mysql_connect(db_host, db_user, db_password) or die("connection failed"); mysql_select_db(db_database,$con) or die("db selection failed"); $r=mysql_query("select tbl_stock.matnum, tbl_stock.sorg, tbl_stock.qty, tbl_mas_material.matname, tbl_mas_material.matgrp tbl_stock inner join tbl_mas_material on tbl_stock.matnum = tbl_mas_material.matnum tbl_stock.qty> 0"); $result = array(); while($row=mysql_fetch_array($r)){ array_push($result, array('matnum'=>$row[0], 'sorg'=>$row[1],'qty'=>$row[2],'matname'=>$row[3],'matgrp'=>$row[4]));} echo json_encode(array("feed"=>$result)); mysql_close($con); ?>
use left join in query. left join keyword returns rows left table (tbl_stock), matching rows in right table (tbl_mas_material).
the result null in right side when there no match.
select tbl_stock.matnum, tbl_stock.sorg, tbl_stock.qty, tbl_mas_material.matname, tbl_mas_material.matgrp tbl_stock left join tbl_mas_material on tbl_stock.matnum = tbl_mas_material.matnum tbl_stock.qty > 0
also suggested saty, add space between tablename , '>' operator. write tbl_stock.qty > 0
Comments
Post a Comment