Current location: Hot Scripts Forums » Programming Languages » PHP » Quicker way of getting number of rows from DB

Quicker way of getting number of rows from DB

Reply
  #1 (permalink)  
Old
Newbie Coder
 
Join Date: Mar 2005
Location: Orlando, Florida
Posts: 77
Thanks: 0
Thanked 0 Times in 0 Posts
Post Quicker way of getting number of rows from DB

Is there a quicker way to get the number of rows for a specific id without using mysql num rows....?
Reply With Quote

Featured Marketplace Scripts (view more)

  #2 (permalink)  
Old
bizzar528's Avatar
Community Liaison
 
Join Date: Sep 2004
Location: Pennsylvania, US
Posts: 1,549
Thanks: 2
Thanked 16 Times in 15 Posts
I don't think so. That function is pretty quick though.

Are you having slow responses for your queries? Maybe a faster query would minimize the time??
__________________
Yep, it's a signature...
Reply With Quote
  #3 (permalink)  
Old
NeverMind's Avatar
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
Quote:
Originally Posted by -[OnTarget]-
Is there a quicker way to get the number of rows for a specific id without using mysql num rows....?
yes! you can use COUNT(*) to get the number of rows!
PHP Code:

$id 'SOME ID HERE';


$fetch mysql_query("SELECT COUNT(*) AS total FROM table_name WHERE id='$id'")or
die(
mysql_error());

$rows mysql_fetch_assoc($fetch);

echo 
$rows['total']; 
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]

Last edited by NeverMind; 03-29-05 at 04:29 PM.
Reply With Quote
  #4 (permalink)  
Old
Newbie Coder
 
Join Date: Mar 2005
Location: Orlando, Florida
Posts: 77
Thanks: 0
Thanked 0 Times in 0 Posts
Yes right now i'm running my site on an old p3 server i picked up for a hundred bucks and its been working great, the only reason i asked this was because when i would try and count the rows of a table, say it had 14,000 entries... it would take about 7 seconds to do, yet when i went into phpMyAdmin it would display it in a few miliseconds without any delay compared to the mysql_num_rows() function....

Thanks for your help!

Wow this is great thanks a bunch, this cut off quite a bit of time off of execution.

Last edited by -[OnTarget]-; 03-29-05 at 06:07 PM.
Reply With Quote
  #5 (permalink)  
Old
bizzar528's Avatar
Community Liaison
 
Join Date: Sep 2004
Location: Pennsylvania, US
Posts: 1,549
Thanks: 2
Thanked 16 Times in 15 Posts
ahhh... thanks nevermind.

I learned something new... that's awesome.
__________________
Yep, it's a signature...
Reply With Quote
  #6 (permalink)  
Old
Newbie Coder
 
Join Date: Mar 2005
Location: Orlando, Florida
Posts: 77
Thanks: 0
Thanked 0 Times in 0 Posts
How would i do the same thing using DISTINCT to just get one type of thing from the db?
Reply With Quote
  #7 (permalink)  
Old
NeverMind's Avatar
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
Quote:
Originally Posted by -[OnTarget]-
How would i do the same thing using DISTINCT to just get one type of thing from the db?
Code:
SELECT COUNT(DISTINCT field_name) AS total FROM table_name;
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #8 (permalink)  
Old
New Member
 
Join Date: Nov 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
yung xxx

If you run Windows 2000, you may require this update before being able to install LibreOffice. Megan cox refer to the corresponding pages on the German site only. Now typing
taking a modern approach to who-you-know data by unifying traditional contact info and social network data, in order to properly represent Pro tools9 for windows7 Otherwise, the upgrade to 3.6.3 may fail.
save money on your international money transfers. Windows 7 home basic 32 bit crack crack.

AVI to MPEG-4 movie format for iPod/PSP or other portable video device, MP4 player or smart phone with Any Video Converter, which also Cast Away Soundtrack ImTOO Video Editor is a professional video editing software comprising functions of Video Joiner, Video Splitter, and Video Cutter. This smart video editor can help you join
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
how to validate mutiple rows using the same input text Han84 JavaScript 1 08-02-07 09:14 AM
add a number every 30 minutes Dion PHP 5 08-31-04 12:52 AM
Updating db with multiple rows Bonzo PHP 1 07-10-04 05:08 PM
Check DB for number perleo PHP 13 04-11-04 01:17 PM


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