Main Menu
How do you Modify the built-in Birthday query to include non-members?
- Date added:
- Saturday, 10 January 2009
- Last revised:
- Thursday, 15 January 2009
Answer
This isn't easy. This article assumes you have some basic knowledge of mySQL, phpMyAdmin, & ChurchDB.
There are two ways to accomplish this:
- Modify the query to include the classifications you desire using phpMyAdmin
- Modify the ChurchDB system to prompt for the classifications you desire when running the Query.
ChurchDB contains a powerful querying system that uses the two SQL tables to store query definitions and parameters. All query definitions are stored in query_qry which is what is displayed when you run the "Query Menu" submenu item from the Data Reports menu. All parameters (options that allow you to select which data you want such as birthmonth in the birthday query" are stored in the queryparameters_qrp table. These tables link together by qry_ID (called qrp_qry_ID in the queryparameters_qry table).
In order to modify the data that a particular query returns when run fron ChurchDB the qry_SQL for the query needs to be updated in the query_qry table. You may notice a strange field such as ~birthmonth~ in the SQL statement stored in this colum. This is used by the ChurchDB system to insert the right values into the SQL query when it comes time to run them from the ChurchDB system.
Option #1: Modify the query to Include the Classifications
- The first step is to determine the classification ID numbers you wish to include in the query. Log into ChurchDB and select the classification manager under People/Family or run the following query through phpMySQL: "Select lst_OptionID as Value, lst_OptionName as Display from list_lst WHERE lst_ID=1 order by lst_optionSequence;". The Values will be the same as the ones obtained in the front-end. Once you have the "ID" numbers proceed to step 2.
- Find the Birthday Query using browse in phpMyAdmin. The Birthday Query will be in the query_qry table and has a qry_ID of 18 and a qry_Name of "Birthdays" by default. Modify the SQL using edit. The numbers in () are for example, use the numbers obtained in step 1.
From:
SELECT per_ID as AddToCart, per_BirthDay as Day, CONCAT(per_FirstName,\' \',per_LastName) AS Name FROM person_per WHERE per_cls_ID=1 AND per_BirthMonth=~birthmonth~ ORDER BY per_BirthDay
TO:
SELECT per_ID as AddToCart, per_BirthDay as Day, CONCAT(per_FirstName,' ',per_LastName) AS Name FROM person_per WHERE per_cls_ID in (1,2) AND per_BirthMonth=~birthmonth~ ORDER BY per_BirthDay - Click go to save. The query when run will now select all the people of the classifications you selected.
- If you prefer a drop down with month names run the following query using phpMyAdmin
CREATE TABLE IF NOT EXISTS `Months` (
`Month` varchar(10) NOT NULL,
`Month_ID` tinyint(2) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO `Months` (`Month`, `Month_ID`) VALUES
('January', 1),
('February', 2),
('March', 3),
('April', 4),
('May', 5),
('June', 6),
('July', 7),
('August', 8),
('September', 9),
('October', 10),
('November', 11),
('December', 12); - This query will create a "Months" table for a lookup, any method of creating this table will work.
- Find the appropriate record out of the queryparameters_qrp table using phpMyAdmin. The record will have a qrp_qry_ID = 18 and a qrp_Alias = "birthmonth". Update the qry_OptionsSQL witht the following:
"Select Month_ID as Value, Month as Display from Months order by Month_ID;" - Click "go" to update the SQL table.
Modify the ChurchDB system to prompt for the classifications you desire when running the Query.
Option #2: Modify the ChurchDB system to prompt for classifications you desire when running the Query:
- Navigate back to the query_qry table and browse the birthday query from step 2 in option 1. Replace the qry_SQL with the following:
"SELECT per_ID as AddToCart, per_BirthDay as Day, CONCAT(per_FirstName,' ',per_LastName) AS Name FROM person_per WHERE per_cls_ID in (~per_cls_id~) AND per_BirthMonth=~birthmonth~ ORDER BY per_BirthDay" - Insert a new record into the queryparameters_qrp table with the following values:
qrp_ID=200
qrp_qry_ID=18
qrp_Type=3
qrp_OptionSQL = "Select lst_OptionID as Value, lst_OptionName as Display from list_lst WHERE lst_ID=1 order by lst_optionSequence;"
qrp_Name = Classifications
qrp_Description "Person Classification (Member, NonMember, etc)"
qrp_Alias = per_cls_id
qrp_Default = 1,2,7,13
qrp_Required = 1
qrp_InputBoxSize = 10
qrp_Validation = l
qrp_NumbericMax, qrp_NumericMin, qrp_AlphaMinLength, qrp_AlphaMaxLength Lef at NULL - Copy this file QueryView.txt over your existing QueryView.php. This patch adds some additional code necassary to deal with setting defaults into the list box (selection box for classifications).
- Test!




