mysql/php count rows

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
cma
Forum Newbie
Posts: 3
Joined: Wed Dec 17, 2008 3:52 pm

mysql/php count rows

Post by cma »

i have this table:

+--+----------+
| page_id | url |
+--+------------+
| 1 | page_1.php |
+--+------------+
| 2 | page_2.php |
+--+------------+
| 3 | page_3.php |
+--+------------+

I want to create a php counter that gets the number of rows in the page_id field, adds them together and then adds one to the answer.

ie. from the table above it would count the rows and come out with 3. then it would add one to it and return the answer of 4.

something like:
$page_id_counter = 0;

then get the code to count the rows. and then:

$page_id_counter = $page_id_counter + 1;

Can anybody suggest a way of doing this? Or alternatively a better method of doing the same sort of thing?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: mysql/php count rows

Post by John Cartwright »

Code: Select all

SELECT COUNT(page_id)+1 AS `count` FROM `yourtable`
Hmm?

Not exactly sure what you described
cma
Forum Newbie
Posts: 3
Joined: Wed Dec 17, 2008 3:52 pm

Re: mysql/php count rows

Post by cma »

thanks that's what I meant exactly!
Post Reply