[PHP-DB] Re: SUM() Math in mySQL

2010-12-20 Thread Ron Piggott

Thanks Chris

I tweaked the query and database a bit so I only do 1 query and use PHP with 
the search results twice:
- initially to calculate the number of records which are in the RSS Feed already
- if that number is less than 15 I make the new rss_feed.xml file using the 
same search results because the SELECT queried for the information I am using 
for this RSS Feed.

Ron

The Verse of the Day
“Encouragement from God’s Word”
http://www.TheVerseOfTheDay.info


From: Ron Piggott 
Sent: Sunday, December 19, 2010 11:38 PM
To: php-db@lists.php.net 
Subject: SUM() Math in mySQL

I am working on the query below.  It’s purpose is to manage the RSS Feed for 
the site.

The part of the query I am struggling with is:

SUM(`include_in_rss_feed`) AS current_rss_feed

What I need is the total value of *ALL* the `include_in_rss_feed` , not the 
specific row.

`include_in_rss_feed` is an integer.  It only ever has a value of 1

My thinking is if the total value of  `include_in_rss_feed` and if it is less 
than 15 the RSS Feed needs to be regenerated because of recent updates to the 
site.

Thanks in advance for helping me.  This is for a clients site, not mine.  I 
really appreciate it.

Ron


SELECT new_rss_feed_listings.reference, new_rss_feed_listings.last_update, 
SUM(`include_in_rss_feed`) AS current_rss_feed, 
`ministry_profiles`.`organization`, `ministry_profiles`.`city`, 
`ministry_profiles`.`province_state`, `ministry_profiles`.`postal_zip_code`, 
`ministry_profiles`.`country`
FROM (
(

SELECT `reference` , `last_update`
FROM `ministry_profiles`
WHERE `live` =1
ORDER BY `last_update` DESC
LIMIT 15
)
UNION ALL (

SELECT `ministry_profiles_reference` , `last_update`
FROM `ministry_profiles_activity`
WHERE `live` =1
GROUP BY `ministry_profiles_reference`
ORDER BY `last_update` DESC
LIMIT 15
)
UNION ALL (

SELECT `ministry_profile_reference` , `last_update`
FROM `ministry_profiles_listing_details`
WHERE `live` =1
GROUP BY `ministry_profile_reference`
ORDER BY `last_update` DESC
LIMIT 15
)
UNION ALL (

SELECT `ministry_profiles_reference` , `last_update`
FROM `ministry_profile_categories`
WHERE `live` =1
GROUP BY `ministry_profiles_reference`
ORDER BY `last_update` DESC
LIMIT 15
)
) AS new_rss_feed_listings 
LEFT OUTER JOIN `rss_feed_listings` ON new_rss_feed_listings.reference = 
`rss_feed_listings`.`ministry_profiles_reference` 
INNER JOIN `ministry_profiles` ON `ministry_profiles`.`reference` = 
new_rss_feed_listings.reference 
ORDER BY new_rss_feed_listings.last_update DESC LIMIT 15

The Verse of the Day
“Encouragement from God’s Word”
http://www.TheVerseOfTheDay.info


Re: [PHP-DB] Re: [PHP] Problems w/ goto

2010-12-20 Thread Daniel Brown
On Sat, Dec 18, 2010 at 17:02, David Hutto smokefl...@gmail.com wrote:
 or maybe it's saturday morning and i'm drunk?

This seems to be the most likely, and considering how all messages
are permanently and independently archived and propagate throughout
the Internet, it might be a good reason not to go nuts in sending
unrelated and unintelligible messages of this nature in the future.

-- 
/Daniel P. Brown
Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Re: [PHP] Problems w/ goto

2010-12-20 Thread David Hutto
On Mon, Dec 20, 2010 at 7:37 AM, Daniel Brown danbr...@php.net wrote:
 On Sat, Dec 18, 2010 at 17:02, David Hutto smokefl...@gmail.com wrote:
 or maybe it's saturday morning and i'm drunk?

    This seems to be the most likely, and considering how all messages
 are permanently and independently archived and propagate throughout
 the Internet, it might be a good reason not to go nuts in sending
 unrelated and unintelligible messages of this nature in the future.

Yeah, that hindsights 20/20 ain't it?


 --
 /Daniel P. Brown
 Network Infrastructure Manager
 Documentation, Webmaster Teams
 http://www.php.net/




-- 
They're installing the breathalyzer on my email account next week.

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php