Current location: Hot Scripts Forums » Programming Languages » PHP » How to count mysql rows?

How to count mysql rows?

Reply
  #1 (permalink)  
Old
Wannabe Coder
 
Join Date: Jun 2004
Posts: 130
Thanks: 0
Thanked 0 Times in 0 Posts
How to count mysql rows?

I wold like to know how to count a certain row (i think its called row )

Orr, maybe it's called records?

Well, let's say I have a field called number, in that number is 7997 records. I would like to know how to count up them records.

Is this possible? :S

//Steve.
Reply With Quote

Featured Marketplace Scripts (view more)

  #2 (permalink)  
Old
Wannabe Coder
 
Join Date: Feb 2004
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
mysql_num_rows is how you would do this.
ex.
PHP Code:

<?php


$link 
mysql_connect("localhost""mysql_user""mysql_password");
mysql_select_db("database"$link);

$result mysql_query("SELECT * FROM table1"$link);
$num_rows mysql_num_rows($result);

echo 
"$num_rows Rows\n";

?>
Reply With Quote
  #3 (permalink)  
Old
darkfreak's Avatar
Newbie Coder
 
Join Date: Jun 2004
Location: Kuopio, Finland, Europe
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
This SQL line works too when counting up rows in the table:

SELECT COUNT(*) FROM sometable;

So if one would like to count up rows where the field named 'number' contains the exact value of 7997, she would do:

SELECT COUNT(*) FROM sometable WHERE number=7997;

Last edited by darkfreak; 08-05-04 at 12:19 AM.
Reply With Quote
  #4 (permalink)  
Old
New Member
 
Join Date: May 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
How about counting a row by today's date?

I recently bought a template site written in PHP and MYSQL. I am pretty familiar with HTML and Flash, but am just learning some PHP and MYSQL now, and I had a question. I have an admin area that I would like to create a fuction to count the rows in a table by the current days date. Any Suggestions?

This is the code I am starting with, but do not know how to get it to count just the current days total for the rows.
PHP Code:

<tr>
  <td height='3' class='text'>No. of Applicants Today</td>
  <td class='text'><?    
$x 
'SELECT appdate, COUNT(*) FROM japplicants WHERE appdate GROUP BY appdate';
$result mysql_query($x) or die(mysql_error());
$total_rows mysql_num_rows($result); 
$row mysql_fetch_row($result); 
print 
"$total_rows"
?></td>
</tr>
Thanks in advance for anyone's help.

Eric

Last edited by Nico; 05-16-09 at 03:36 AM.
Reply With Quote
  #5 (permalink)  
Old
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
PHP Code:

$x 'SELECT COUNT(*) FROM japplicants WHERE appdate=CURDATE()';

$result mysql_query($x) or die(mysql_error());
$total_rows mysql_fetch_row($result);
print 
$total_rows[0] . ' People have posted applications today.'
This should work IF the appdate column is a type DATE column.
Reply With Quote
  #6 (permalink)  
Old
Vicious's Avatar
Community VIP
 
Join Date: Jan 2007
Location: Belgium
Posts: 584
Thanks: 0
Thanked 0 Times in 0 Posts
The above is good enought for what SiddallStudios is requesting, but for the sake of completeness, here's an example query for any date:

Code:
SELECT count(*) FROM japplicants WHERE DATE_FORMAT(appdate,'%Y%m%d') = "20090425";
__________________
Jack Bauer makes Chuck Norris cry
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
delete duplicate rows in mysql using php seans9 PHP 4 07-16-08 09:42 PM
Double count possible in MySQL? TGOS PHP 4 05-17-04 09:17 AM
PHP MYSQL Count Help Darren884 PHP 2 02-16-04 05:08 AM
MySQL random rows query unclematty PHP 5 11-25-03 04:03 PM


All times are GMT -5. The time now is 03:26 AM.
vBulletin® Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.