/    Sign up×
Community /Pin to ProfileBookmark

Problem in syntax from mysql to php syntax

Hi..

I create mysql syntax for query testing before i input to my php code

here is my mysql code:

[code]
set @t = 0;
set @rqty=31968;
SELECT LOT_CODE as code, DATE_ENTRY,
CASE WHEN @t+OUTPUT_QTY > @rqty
THEN @rqty -@t
ELSE OUTPUT_QTY
END as qty,
@t := @t + d.OUTPUT_QTY as cumulative
FROM dipping d WHERE SUBSTR(LOT_CODE, 9,4) = ‘P28’ AND (@t < @rqty);
[/code]

and i attach the sample output of the above query.

Now that query test is work i will input that code to my php codes.

[code=php]
$sql = “SELECT SKUCode, Materials, Comp, Qty
FROM bom WHERE SKUCode = ‘$SKUCode'”;
$res = mysql_query($sql, $con);

($row = mysql_fetch_assoc($res));
$Materials = $row[‘Materials’];
$Qty = $row[‘Qty’];
$Comp = $row[‘Comp’]; //P28
//—–Compute Req Qty and Save to table—//

$ReqQty = $Qty * $POReq; // 31968

$sql = “UPDATE bom SET ReqQty = ‘$ReqQty’ WHERE SKUCode = ‘$SKUCode’ AND Materials = ‘$Materials'”;
$resReqQty = mysql_query($sql, $con);

$t = 0;

$sql = “SELECT LOT_CODE as code, DATE_ENTRY,
CASE WHEN $t+OUTPUT_QTY > $ReqQty
THEN $ReqQty -$t
ELSE OUTPUT_QTY
END as qty,
$t := $t + d.OUTPUT_QTY as cumulative
FROM dipping d WHERE SUBSTR(LOT_CODE, 9,4) = ‘$Comp’ AND ($t < $ReqQty)”;
[/code]

when I echo the query:

I got this:

SELECT LOT_CODE as code, DATE_ENTRY, CASE WHEN 0+OUTPUT_QTY > 31968 THEN 31968 -0 ELSE OUTPUT_QTY END as qty, 0 := 0 + d.OUTPUT_QTY as cumulative FROM dipping d WHERE SUBSTR(LOT_CODE, 9,4) = ‘P28’ AND (0 < 31968)

then I run it to the sql

and I got an error:

Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘:= 0 + d.OUTPUT_QTY as cumulative FROM dipping d WHERE SUBSTR(LOT_CODE, 9,4) = ” at line 1
(0 ms taken)

Any help is highly appreciated

Thank you so much

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@DasherMay 16.2012 — MySQL does not have a SUBSTR() function it is SUBSTRING()

[I]SUBSTRING(str,pos) , SUBSTRING(str FROM pos) , SUBSTRING(str,pos,len) , SUBSTRING(str FROM pos FOR len) [/I]
×

Success!

Help @newphpcoder spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...