Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old April 9th, 2003, 10:04 PM
iloop iloop is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 1 iloop User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to iloop
help with count(*)

Hey there,

I've got a tagboard where I want to only show the last 10 entries.

to get all of the tagboard items I do:

php Code:
Original - php Code
  1. $query = sprintf ("SELECT * FROM tagboard");
  2.     $res = mysql_query($query, $dbh);


so next I try to get the count of items with:

php Code:
Original - php Code
  1. $query2 = "select count(*) from tagboard";
  2. $count = mysql_query ($query2,$dbh);


the problem with this is that I don't seem to be getting the actual number back to $count. When I try to print it I get 'Resource id #2'.

I was thinking of doing something like:

php Code:
Original - php Code
  1. $last10 = $count -10;


then:

php Code:
Original - php Code
  1. select * from tagboard where id>$last10;


thanks for any help!

Reply With Quote
  #2  
Old April 10th, 2003, 02:38 AM
Matt Matt is offline
Contributing User
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: help with count(*)

change:

$count = mysql_query ($query2,$dbh);

to:

$result = mysql_query($query2,$dbh);
$row = mysql_fetch_row($result);
$count = $row[0];


But, a better way would be to use a query such as:

SELECT * FROM tagboard ORDER BY id DESC LIMIT 10

that will get you the 10 items from the tagboard table with the largest id's.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > help with count(*)


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