mysql_num_rows()

Can anybody see what’s wrong here?

It doesn’t give an error or work.

  $query1 = mysql_query("SELECT * FROM naturehills") or die(mysql_error());
  $num_of_rows_naturehills = mysql_num_rows($query1) or die(mysql_error());

  $query2 = mysql_query("SELECT * FROM naturehills_load") or die(mysql_error());
  $num_of_rows_maintable = mysql_num_rows($query2) or die(mysql_error());

  $num_of_rows_maintable - $num_of_rows_naturehills = $total_new_items_added;
  1. have you confirmed you are connected to the database?

  2. put

 
echo 'got here';
die();

just above your code to confirm your script actually gets there.

Yes, it connected because this code is added to the bottom of database update. …and the database updates!

what about 2) then ?

$total_new_items_added = $num_of_rows_maintable - $num_of_rows_naturehills;

Defining a variable needs be done before assigning a value to it.

If your talking about the two “)” I didn’t add or die(mysql_error()); until after it didn’t work. When I remove one like this or die(mysql_error(); I get the following error.

Parse error: syntax error, unexpected ‘;’ in /homepages/18/d346921776/htdocs/Home/4742/4742_db_load.php on line 155

This doesn’t work either???

 $num_of_rows_maintable - $num_of_rows_naturehills = $total_new_items_added;
	// Query the database and get the count
  $query1 = mysql_query("SELECT * FROM naturehills") or die(mysql_error());
  $num_of_rows_naturehills = mysql_num_rows($query1) or die(mysql_error());

  $query2 = mysql_query("SELECT * FROM naturehills_load") or die(mysql_error());
  $num_of_rows_maintable = mysql_num_rows($query2) or die(mysql_error());

After put the variables on top I think its working now .

Thanks!

i can :slight_smile:

you’re pulling in all the rows from the database tables, and counting them in php

it’s ~far~ more efficient to let mysql count them, and return just the count to you

heck, you can even do it in one query:

SELECT ( SELECT COUNT(*) 
           FROM naturehills_load ) -
       ( SELECT COUNT(*) 
           FROM naturehills ) AS total_new_items_added

:slight_smile:

That’s better!

At my level on the learning curve I feel lucky if it works at all. :slight_smile:

and if they are myisam tables, that query comes back in only a few thousandths of a second, because mysql maintains current counts for myisam tables

it’s kind of like the following analogy i’m very fond of…

suppose you and i are sitting in an office in new york, and i ask you to find out the population of los angeles

one way is for you to get everybody in los angeles to fly over to new york, and you count them as they get off the plane(s)

the other way is for you to go to los angeles, count them there, and come back with the answer

which do you think is more efficient?

and if it’s a myisam table, it’s even more efficient, you simply go to los angeles, look up the number in the population registry, and come back immediately

in a database environment, shipping the entire contents of a table between the database and the application is a huge bottleneck (just as putting people on a plane is)

:cool: