yshua Posted December 28, 2012 Share Posted December 28, 2012 Dear forum people: Have PHP5.3.8, MySQL5.17, Apache2.2, Win 7. Am using too many languages at once. Still need to catch up learning how to store a record's fields into variables before using mysql_free_result(): $chk_txnid = "SELECT 1, orderno, status FROM mytable WHERE txn_id='$tx_token'"; $result = mysql_query($chk_txnid); $num_rows = mysql_num_rows($result); Later this is followed with, mysql_free_result($result); The system gives me the error to use mysql_free_result unless it appears before the update. Then the following code yields zero updates: $query = "UPDATE mytable SET status=1 , txn_id='$tx_token' where orderno ='$orderno'"; Can someone answer any of the two following questions: How to store the read in record as variables, and How to use a mysql_free_result() command AFTER the above update. Grabbing at straws, Yshua Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 28, 2012 Share Posted December 28, 2012 (edited) The PHP Manual goes over how to use all the mysql functions, with detailed examples. Ignoring the fact that you should be using mysqli and you generally don't need to free the result, mysql_fetch_assoc should help. Edited December 28, 2012 by Jessica Quote Link to comment Share on other sites More sharing options...
DavidAM Posted December 28, 2012 Share Posted December 28, 2012 The stated question is not very clear, and the provided snippets do not provide much insight. If you want to collect all of the data from the query ... $data = array(); // Where we will store the data $foundRows = 0; // Number of rows returned $sql = 'SELECT ...'; if ($res = mysql_query($sql)) { $foundRows = mysql_num_rows($res); while ($row = mysql_fetch_assoc($res)) { $data[] = $row; } mysql_free_result($res); } Although, doing $foundRows = count($data) after the loop will provide the same answer as mysql_num_rows() in this case. I don't know what error you might be getting for not freeing the result before you do the another query (to update). If all you want is the number of rows, then don't select the data back, just select a count: $sql = 'SELECT COUNT(*) FROM table WHERE condition = true'; if ($res = mysql_query($sql)) { $foundRows = mysql_result($res, 0, 0); mysql_free_result($res); } else { $foundRows = 0; } 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.