Free2Code
 
Time: 2008-12-04, 07:37pm
More PHP and MySQL questions....
Subject: More PHP and MySQL questions....  ·  Posted: 2007-08-04, 04:30pm
Rank: ? (4280)
Member #: 5260
Is there a PHP function that return the total number of records in a table?

Dreams are stories, but my life is just one bad dream. :P
 
  Reply to this ·  Post link ·  Top
Subject: Re: More PHP and MySQL questions....  ·  Posted: 2007-08-04, 06:00pm
Rank: ? (767)
Member #: 11085
If by table, you mean a MySQL table, then yes, there is. mysql_num_rows(), along with a query selecting all rows of a table (for instance, "SELECT * FROM `table`") would give you the total number of records.

- relpats_eht
 
  Reply to this ·  Post link ·  Top
Subject: Re: More PHP and MySQL questions....  ·  Posted: 2007-08-04, 06:09pm
Rank: ? (4280)
Member #: 5260
I was hoping for function that didn't require query of selecting all.

Oh, well.

Thanks, relpats_eht. smile

Dreams are stories, but my life is just one bad dream. :P
 
  Reply to this ·  Post link ·  Top
Subject: Re: More PHP and MySQL questions....  ·  Posted: 2007-08-05, 09:33am
Rank: ? (767)
Member #: 11085
Code:
  1. <?php
  2. function MySQLNumRows($table){
  3.     return mysql_num_rows(mysql_query("SELECT * FROM `$table`"));
  4. }
  5. ?>


...?

» Post edited 2007-08-05, 09:33am by relpats_eht.

- relpats_eht
 
  Reply to this ·  Post link ·  Top
Subject: Re: More PHP and MySQL questions....  ·  Posted: 2007-08-05, 11:44am
Rank: ? (4280)
Member #: 5260
Creating a function to do this. I should have thought of that. tongue

*Mr Grumpy angry bangs his head on the desk*

Ow! eek OW! eek OW!!! eek Stop that you're hurting our head. eek

Again, thank you, relpats_eht. smile

Dreams are stories, but my life is just one bad dream. :P
 
  Reply to this ·  Post link ·  Top
Subject: Re: More PHP and MySQL questions....  ·  Posted: 2007-08-05, 05:20pm
Rank: ? (767)
Member #: 11085
If you use that function, make sure not to pass any user data to it. It isn't secure.

- relpats_eht
 
  Reply to this ·  Post link ·  Top

Pages: 1

Please login or register to post a reply.

icons