Jump to content

Recommended Posts

if you don't have "date submitted" field or you want to grab the highest id row of some other table you can use num_row to produce the id number for your query

 

http://us2.php.net/mysql-num-rows

 

One would hope that a table full of news would have dates/times associated with them...

if you don't have "date submitted" field or you want to grab the highest id row of some other table you can use num_row to produce the id number for your query

 

That's the worst idea I've ever heard.  The method you are suggesting is to do:

 

$query = "SELECT id FROM table";
$result = mysql_query($query);
echo "Number of rows in table is " . mysql_num_rows($result);

 

What if there is 100000 rows in the table?  That query is now returning everyone one of them to php which then must count them to get the result...at a minimum it would take 15-20 seconds to do the retrieve and then send the rows to php, not counting any other processing.  It makes much, MUCH more sense to do the counting in the database:

 

$query = "SELECT COUNT(id) FROM table";
$result = mysql_query($query);
echo "Number of rows in table is " . mysql_result($result, 0);

 

If the table is a MyISAM table, then the latter query's result is near instant.  If it's InnoDB, and you are counting on an indexed column (and you should be), then it is again, near instant.

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.