Jump to content

Query not working


Recommended Posts

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 ……..


Link to comment
Share on other sites

"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.

Link to comment
Share on other sites

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



Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...