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
Advertisement
Associates
Associates
techtuts Darkmindz
CSS Tutorials Tutorialsphere.com - Free Online Tutorials
Boston PHP SurfnLearn
Reply
 
LinkBack Thread Tools Display Modes
Old 09-26-2007, 09:21 AM   #1 (permalink)
The Contributor
 
marxx's Avatar
 
Join Date: Sep 2007
Location: Finland
Posts: 40
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, 12:44 PM   #2 (permalink)
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 436
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
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 06:37 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0