Use output of one function in another of the same class
Posted: Wed Feb 17, 2010 8:30 am
Hello,
I would like to create a class to help building dynamic SQL Queries.
This class will contain, a.o., a function that will use the output of another function contained in the same class.
The code I have now is as follows:
<?php
class EMail_Helper
{
function Handle_Auto_EMail($User_Category, $User_ID, $List_Dossiers) {
$SQL_IN_Part = $This->Build_IN_SQL_Part($List_Dossiers);
....
}
function Build_IN_SQL_Part($List_Dossiers) {
$TestStr = explode('|', $List_Dossiers);
$i = 0;
$In_Statement = ' IN (';
while ($i < count($TestStr))
{
$In_Statement = $In_Statement . $TestStr[$i] . ', ';
$i++;
}
$In_Statement = trim($In_Statement);
$In_Statement = substr($In_Statement,0, strlen($In_Statement)-1);
$In_Statement = $In_Statement . ')';
Return $In_Statement;
}
}
?>
My objective is to build the query using one single call to the function i.e.:
...
$Cls_EMail_Helper = new EMail_Helper();
...
$Cls_EMail_Helper->Handle_Auto_EMail('VET',$current_vet, $Vet_Dossiers);
...
where $Vet_Dossiers is a pipe separated list.
The issue I face is that although Build_IN_SQL_Part provides the expected output string, I am unable to retrieve it in the $SQL_IN_Part variable of the first function.
Thnak you
Michel
I would like to create a class to help building dynamic SQL Queries.
This class will contain, a.o., a function that will use the output of another function contained in the same class.
The code I have now is as follows:
<?php
class EMail_Helper
{
function Handle_Auto_EMail($User_Category, $User_ID, $List_Dossiers) {
$SQL_IN_Part = $This->Build_IN_SQL_Part($List_Dossiers);
....
}
function Build_IN_SQL_Part($List_Dossiers) {
$TestStr = explode('|', $List_Dossiers);
$i = 0;
$In_Statement = ' IN (';
while ($i < count($TestStr))
{
$In_Statement = $In_Statement . $TestStr[$i] . ', ';
$i++;
}
$In_Statement = trim($In_Statement);
$In_Statement = substr($In_Statement,0, strlen($In_Statement)-1);
$In_Statement = $In_Statement . ')';
Return $In_Statement;
}
}
?>
My objective is to build the query using one single call to the function i.e.:
...
$Cls_EMail_Helper = new EMail_Helper();
...
$Cls_EMail_Helper->Handle_Auto_EMail('VET',$current_vet, $Vet_Dossiers);
...
where $Vet_Dossiers is a pipe separated list.
The issue I face is that although Build_IN_SQL_Part provides the expected output string, I am unable to retrieve it in the $SQL_IN_Part variable of the first function.
Thnak you
Michel