![]() |
Admin 10/23/2006 |
Hi, |
T
|
thesofa author 10/23/2006 |
Hi, I recommend you to create a view in your database with CREATE VIEW command then use this view in PHPRunner. Then you'll be able to search on aggregate values without any code modifications.
select `ID` ,
|
![]() |
Admin 10/23/2006 |
Hi, create view myview as select `ID` , count(ID) as Total, `DateGiven`, `detainee` , `donor` , ...
`TutorGroup`CONTAINS "xxxx" AND `DateGiven` BETWEEN xx/xx/xxxx and xx/xx/xxxx AND Total>=3 |
T
|
thesofa author 10/23/2006 |
Once again, I am not being clear in my request, i feel. |
![]() |
Admin 10/23/2006 |
Hi, $strSQL = AddWhere($strSQL,$strWhere);
$strSQL .= " having ".$strWhere;
$strSQL = AddWhere($strSQL,$sWhere);
$strSQL .= " having ".$sWhere;
|
T
|
thesofa author 10/23/2006 |
Hi, I see what you saying. You can replace WHERE with HAVING in generated ..._list.php file. Find this line there: and replace it with: Then find this one: and replace it with: I don't guarantee this would work with Master-detail relationship or with Advanced Security.
|
T
|
thesofa author 10/23/2006 |
I have tried this and it produces a query like this select count(ID) as Total, `DateGiven`, `detainee` , `DayForDetention`, `sess`, `Done`, `Origin`, `pupils`.`lname`, `sessions`.`sess_time`, concat(`pupils`.`fname`,' ',`pupils`.`lname`) AS `Pupil`, `detentions`.`reason`, concat(left(`staff`.`firstname`,1),'. ',`staff`.`lastname`) AS `Teacher` from ((((`detentions` inner join `pupils` on((`pupils`.`idPupil` = `detentions`.`detainee`))) inner join `reasons` on((`reasons`.`idReason` = `detentions`.`reason`))) inner join `sessions` on((`sessions`.`sess_id` = `detentions`.`sess`))) inner join `staff` on((`staff`.`userid` = `detentions`.`donor`))) inner join `dept` on((`dept`.`idDept` = `detentions`.`department`)) Group By `ID` having 1=1 and `detentions`.`DateGiven`>='2006-10-02 00:00:00' and `detentions`.`DateGiven`<='2006-10-13 00:00:00' and `detentions`.`Total`>=3 ORDER BY `pupils`.`lname` ASC
Unknown column 'detentions.Total' in 'having clause'
SELECT
SELECT it only returns half the records.. It would seem that the use of having excludes any pupils who have detentions outside the date range specified, even if they have some inside the range. |
T
|
thesofa author 10/24/2006 |
bump |
![]() |
Admin 10/24/2006 |
Hi, select ... WHERE `detentions`.`DateGiven` >= '2006-10-02 00:00:00' AND `detentions`.`DateGiven` <= '2006-10-13 00:00:00' AND `detentions`.`TutorGroup` LIKE '7%' GROUP BY `detentions`.`detainee` Having Count(`detentions`.`ID`)>=3 ORDER BY `detainee` ASC
else if(@$_SESSION[$strTableName."_search"]==2) // advanced search { $sWhere=""; foreach(@$_SESSION[$strTableName."_asearchfor"] as $f => $sfor) { $strSearchFor=trim($sfor); $strSearchFor2=""; $type=@$_SESSION[$strTableName."_asearchfortype"][$f]; if(array_key_exists($f,@$_SESSION[$strTableName."_asearchfor2"])) $strSearchFor2=trim(@$_SESSION[$strTableName."_asearchfor2"][$f]); if($strSearchFor!="" || true) { if (!$sWhere) { if($_SESSION[$strTableName."_asearchtype"]=="and") $sWhere="1=1"; else $sWhere="1=0"; } $strSearchOption=trim($_SESSION[$strTableName."_asearchopt"][$f]); if($where=StrWhereAdv($f, $strSearchFor, $strSearchOption, $strSearchFor2,$type)) { if($_SESSION[$strTableName."_asearchnot"][$f]) $where="not (".$where.")"; if($_SESSION[$strTableName."_asearchtype"]=="and") $sWhere .= " and ".$where; else $sWhere .= " or ".$where; } } } $strSQL = AddWhere($strSQL,$sWhere); }
|
T
|
thesofa author 10/24/2006 |
Hi Alexy, thanks for the snippet, I had come to the same conclusion as you, I need WHERE and HAVING. |
T
|
thesofa author 10/25/2006 |
bump |
![]() |
Admin 10/26/2006 |
Hi, |
T
|
thesofa author 10/26/2006 |
Hi, $f variable in the code contains a field name. $where - a search criteria for a given field all you need is to combine search criterias properly.
|
T
|
thesofa author 10/29/2006 |
I have been thinking for a change, if I create a temporary table of the data I need for the search to work, I can have a column of the count of the detentions, with the value created as the table is written. This table will have to be named with the name or identifyer of the logged in user, and it will have to be emptied and dropped after each use. |
T
|
thesofa author 10/29/2006 |
I think I have cracked it. Count(`ID`) AS `Total`,
// order by
$strSQL = AddWhere($strSQL,$sWhere);
." HAVING `Total` >= '3'"
$strSQL = AddWhere($strSQL,$sWhere)." HAVING `Total` >= '3'";
|