TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-26-2007, 08:21 AM   #1 (permalink)
The Contributor
 
marxx's Avatar
 
Join Date: Sep 2007
Location: Finland
Posts: 45
Thanks: 3
marxx is on a distinguished road
Default Count multiple tables + same row name

Hi!

How to count from multiple tables where all has same rowname?

table: commentsimage
rowname: poster

table: commentsprofile
rowname: poster

table: commentscafe
rowname: poster

I have tryed something like this which doesn't work tho..
PHP Code:
$count mysql_query("SELECT COUNT(poster) FROM commensimage, commentsprofile, commentscafe WHERE poster = $poster") or die(mysql_error()); 

Thanks for all help!
Send a message via MSN to marxx
marxx is offline  
Reply With Quote
Old 09-26-2007, 11:44 AM   #2 (permalink)
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 437
Thanks: 22
Karl is on a distinguished road
Default

Hi there, try the following code

PHP Code:
 $count mysql_query("    SELECT 
                COUNT(DISTINCT commensimage.poster) as commensimage_count,  
                COUNT(DISTINCT commentsprofile.poster) as commentsprofile_count, 
                COUNT(DISTINCT commentscafe.poster) as commentscafe_count 
            FROM 
                commensimage, commentsprofile, commentscafe 
            WHERE 
                poster = 
$poster;") or die(mysql_error()); 
THis should return 3 seperate counts. If you wanted to add them all together and return the total, you can do something like this:

PHP Code:
SELECT 
                COUNT
(DISTINCT commensimage.poster) + 
                
COUNT(DISTINCT commentsprofile.poster) +
                
COUNT(DISTINCT commentscafe.poster) as total_count 
            FROM 
Karl is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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


All times are GMT. The time now is 08:38 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design