Jump to content

Archived

This topic is now archived and is closed to further replies.

intro9

get single value from query

Recommended Posts

Im' a green beginner here and I'm having a small problem I'm sure somebody can solve fairly quickly. I am trying to write a few lines of code that removes as many items from my database as are in the persons shopping cart. I just can't get the script to get the quantity value out of the cart database.

 

 

 

$quantity = mysql_query("select qty from cart where cookieId = '" . GetCartId() . "' and itemId");

 

mysql_query("update items set stockcount = stockcount - '" . $quantity . "' where itemId = $itemId");

 

 

 

I want to update the items table to decrease the stockcount by the amount the person purchased, aka the value in the qty field in the persons cart.

 

I want the $quantity variable to be equal to the qty of the current item in my cart. database. as shown below. I know I am taking the full row in my first line of code, which is COMPLETELY wrong, but what is the correct method of getting that single value from the cart table, the qty value into the $quantity variable so I can use it in my stockcount deduction?

 

Thanks in advance!

 

Frank

Share this post


Link to post
Share on other sites
$result = mysql_query("select qty from cart where cookieId = '" . GetCartId() . "' and itemId"); // might have something wrong with your query as well
$quantity = mysql_result($result,0,0);

Share this post


Link to post
Share on other sites

Thank you Soooooo much, that worked great! You know, I tried something similar a few times, but I was just a hair off on both previous attempts. Good to know I was on the right track tho, and thanks for the lightning quick response. I'm very thankful!

 

Sincerely,

Frank

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.