Jump to content
Sign in to follow this  
mickeymouse

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

 

Share this post


Link to post
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.

Share this post


Link to post
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)) 

        print("...…..

Tks

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...