Jump to content


Photo

get single value from query


  • Please log in to reply
2 replies to this topic

#1 intro9

intro9
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 19 October 2005 - 09:22 PM

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

#2 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 19 October 2005 - 09:28 PM

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

Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#3 intro9

intro9
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 19 October 2005 - 09:32 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users