mickeymouse 0 Posted December 5, 2019 Report Share Posted December 5, 2019 I'm getting 0 in $AffectedRows and get my resulting message "There are no transactions..." Yet, I have many records in my "transactions" DB file. I Can't understand, can't see any errors in my code. I don't get any DB errors nor any other errors. The same code (for other DB files) works fine. $link = mysql_connect($host, $username, $password); if (!$link){die('Not connected : ' . mysql_error());} $db_selected = mysql_select_db($database, $link); if (!$db_selected){die ('Can\'t use ' .$database .':'. mysql_error());} $query = "SELECT * FROM `transactions` "; $Results = mysql_query($query, $link) or die ('Error = '. mysql_error()); $AffectedRows = mysql_affected_rows($link); if($AffectedRows < 1) {print("There are no transactions …….. Quote Link to post Share on other sites
Ingolme 1,035 Posted December 5, 2019 Report Share Posted December 5, 2019 "Affected rows" usually only counts the number of rows that were modified or deleted. If you want to count the number of rows that were selected, you can either loop through the rows you received and count them or or use a SELECT COUNT(*) query. Quote Link to post Share on other sites
mickeymouse 0 Posted December 6, 2019 Author Report Share Posted December 6, 2019 Very well but 1) How do I test the COUNT? 2) I tried $MyRowCount=mysql_num_rows(); (according to SQL Documentation) and I get 0 rows read, yet the DB has some 1000 rows. 3) Ignoring the counting aspect, I list the rows read with following code but there are no rows. So the real question besides the counting is "Why is it not reading the rows?" while ($row = mysql_fetch_row($Results)) print("...….. Tks Quote Link to post Share on other sites
Ingolme 1,035 Posted December 6, 2019 Report Share Posted December 6, 2019 The mysql_ library is deprecated, you should be using something else like PDO. I can't tell what the problem is without seeing all of the code. Can you write a very basic program to test it and put the code here? Please use the code block ( <> button) to keep it organized. Quote Link to post Share on other sites
mickeymouse 0 Posted December 6, 2019 Author Report Share Posted December 6, 2019 OK. I found the problem. One of my field parameters for selection did not contain the correct info and the Affected Rows = 0 was indeed correct. It is now working (and Affected Rows is giving me the correct count). Regrets for taking up your time. Thank you. Quote Link to post Share on other sites
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.