General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 27th, 2003, 03:52 AM
wastedbreath wastedbreath is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: BC, Canada
Posts: 35 wastedbreath User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to wastedbreath
Counting entries

Hey everybody.
Been working on my personal site lately and decided to add a section, 'Random Hotties'.

The idea is to search the database for the number of entries, choose a random number and then show that image. My problem comes to counting how many entries are in the table I select.

I'm sure it's some really simple MySQL command, but I'm too tired to see it in Google. Any help would be appreciated, and I might not reply back quickly, I will be out of town and away from computers for about a week.
__________________
My Site in the works

Reply With Quote
  #2  
Old December 27th, 2003, 10:26 PM
Mike_r Mike_r is offline
ExoCrew
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 68 Mike_r User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
You can use this command to count the number of enteries:

$QUERY = mysql_query ( "SELECT * FROM TABLE" );
$COUNT = mysql_num_row( $QUERY );
__________________
ExoHelpDesk
ExoCrew Free Services

Reply With Quote
  #3  
Old December 29th, 2003, 08:20 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
It'd probably be easier to do something like the following:

Code:
SELECT id FROM table ORDER BY RAND() LIMIT 1


This gives you a random id without requiring that you first do a count.

Reply With Quote
  #4  
Old December 29th, 2003, 11:49 AM
Bruski Bruski is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 192 Bruski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
wouldnt this also work
PHP Code:
<? SELECT count(idFROM table WHERE id=$id ?>

Reply With Quote
  #5  
Old December 29th, 2003, 04:28 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Bruski, he's wanting a random number, not a count of the id in question. Also, conceivably, the row corresponding to a count of the id could possibly have been deleted, resulting in a display error. Mike_r's method is doable, but would require then taking the count and running a PHP function on it to get a random number not greater than that count. My query does all that work in one step.

Reply With Quote
  #6  
Old January 1st, 2004, 07:59 PM
wastedbreath wastedbreath is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: BC, Canada
Posts: 35 wastedbreath User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to wastedbreath
Excellent, thanks guys. I'll try when I get home.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Counting entries


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT