1

I have the following query:

    SET @q = 12;  
    UPDATE `table` 
    SET qty = CONCAT(GREATEST(qty - @q, 0), LEFT(@q := @q - LEAST(qty, @q), 0)) 
    ORDER BY id; 

(Go vote eggyal up for the great query here: Removing a quantity from multiple rows in a database )

I am running the query (without preparing in this case) through OOP PDO / MySQL.

I want to pass the value of the @q back to PHP or any flag really if @q did not get to 0. I'm not sure how to accomplish this. If anyone is able to point me in the right direction, I'd appreciate it.

Thanks

2 Answers 2

1

Just select it, as you would anything else:

$res = mysql_query("SELECT @q AS q") or die(mysql_error());
$row = mysql_fetch_assoc($res);
echo $row['q'];
Sign up to request clarification or add additional context in comments.

Comments

1

Doesn't this work:

$res = mysql_fetch_array( mysql_query( "SELECT @q" ) );
print_r( $res );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.