fsl4faisal Posted October 9, 2010 Share Posted October 9, 2010 i want to store a value from a database and use it as variable in php code can anyone help me out in this code i want to store value of copies in a php variable and want that it should be more than 0 (zero) for furthur calculations $update_book="update book set copies=copies-1 where bookid='$bookid'"; $result=mysql_query($update_book,$linkID1); if($result) { print "<html><body background=\"header.jpg\"> <p>book successfully subtracted from database</p></body></html>"; } else { print "<html><body background=\"header.jpg\"> <p>problem occured</p></body></html>"; } Quote Link to comment Share on other sites More sharing options...
ialsoagree Posted October 9, 2010 Share Posted October 9, 2010 $select_copies = 'SELECT copies FROM book WHERE bookid= \''.$bookid.'\''; $select_result = mysql_query($select_copies, $linkID1); if ($select_result && mysql_num_rows($select_result) > 0) { $copies_array = mysql_fetch_assoc($select_result); $num_of_copies = $copies_array['copies']; // $num_of_copies is the variable that contains the number of copies } else { // Invalid $bookid, process error here } This code assumes that every $bookid is for a unique book and therefor will only return 1 or 0 results (0 results if that $bookid does not exist). That what you're looking for? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.