SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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);
    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.

    PHP Code:
         $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)"

    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
    Attached Images Attached Images

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,247
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:

    Circular references! Rudy leading me around and around....
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,247
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Off Topic:

    it's not me doing it, it's newphpcoder, i'm just pointing out his multiple threads
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •