dave4dl
asked on
more php reference problems
The values in a custom object i have dont seem to be being accessed correctly and i think it is because i am not using references correctly in php (I am new to php). Below is my code with comments showing the odd output. Below the code is the output (read the description above the output to see what is wrong with it).
function controlOutput(){
//pull all the unique key/display values from tablename
$output="";
$controlName=$this->parent Column->ge tControlNa me();
$output=$output."<select name=\"".$controlName."\" id=\"".$controlName."\">";
if($this->strKeyColumn!="" ){
$result=$this->queryDataba se();
while($row = mysql_fetch_row($result))
{
$id = $row[0];
$display = $row[1];
$output=$output."<option value=\"$id\"";
echo "Test2? - \$this->parentColumn->strC urValue={$ this->pare ntColumn-> strCurValu e}<br>\n"; // <-this prints out blank
//echo "\$id=$id\n";
if($this->parentColumn->st rCurValue= =$id) $output=$output." selected";
$output=$output.">$display </option>\ n";
}
$output=$output."</select> ";
}
return $output;
} //end function controlOutput()
function editOutput(){
//pull all the unique key/display values from tablename
$output="";
$controlName="frm_".$this- >strTableN ame;
$output=$output."<form name=\"".$controlName."\" id=\"".$controlName."\" action=\"".$_SERVER['SCRIP T_NAME']." \" method=\"POST\">";
$output=$output."<table cellpadding=0 cellspacing=0 border=0 align=left>";
foreach ($this->arrColumns as $i => $value){
$output=$output."<tr>";
$output=$output."<td nowrap style=\"padding-bottom:3px \">".$valu e->descrip tionOutput () . "</td>";
$output=$output."<td nowrap style=\"padding-left:5px;p adding-bot tom:3px\"> ".$value-> controlOut put() . "</td>";
$output=$output."</td></tr >\n";
}
$output=$output."</table>< br clear=\"left\" />";
foreach ($this->arrHiddenFormVaria bles as $i => $value){
$output=$output."<input type=\"hidden\" name=\"{$value[0]}\" id=\"{$value[0]}\" value=\"{$value[1]}\">";
}
$output=$output."<br /><input type=\"submit\" value=\"Save Changes\">";
$output=$output."</form>";
return $output;
} // end function editOutput
$objCurTable->strIdColumnV alue=$curI D;
if(strtolower($curAction== "edit")){
$objCurTable->updateFromDa tabase();
foreach($objCurTable->arrC olumns as $foreachCurColumn){
echo "Test? - \$foreachCurColumn->strCur Value{$for eachCurCol umn->strDi splayText} ={$foreach CurColumn- >strCurVal ue}<br />\n"; <--actually holds the value
}
}
echo $objCurTable->editOutput() ;
-------------------------- ---------- ---------- ---------- ---------- ---------
The following is output generated from the code above. Notice that during "Test2" the columns have values but during "Test" they do not:
Test? - $foreachCurColumn->strCurV alueProgra m Name=Example Entry
Test? - $foreachCurColumn->strCurV alueProgra m Description=
Test? - $foreachCurColumn->strCurV alueProgra m Website=
Test? - $foreachCurColumn->strCurV alueThis program is also an instition=1
Test? - $foreachCurColumn->strCurV alueProgra m institution=376
Test2? - $this->parentColumn->strCu rValue=
^^ The above line is repeated for each record in $result (in the controlOutput function)^^
Does anyone know why I am seeing this output and what changes to make so it see the strCurValues when it runs Test2 (in addition to "Test?")?
function controlOutput(){
//pull all the unique key/display values from tablename
$output="";
$controlName=$this->parent
$output=$output."<select name=\"".$controlName."\" id=\"".$controlName."\">";
if($this->strKeyColumn!=""
$result=$this->queryDataba
while($row = mysql_fetch_row($result))
{
$id = $row[0];
$display = $row[1];
$output=$output."<option value=\"$id\"";
echo "Test2? - \$this->parentColumn->strC
//echo "\$id=$id\n";
if($this->parentColumn->st
$output=$output.">$display
}
$output=$output."</select>
}
return $output;
} //end function controlOutput()
function editOutput(){
//pull all the unique key/display values from tablename
$output="";
$controlName="frm_".$this-
$output=$output."<form name=\"".$controlName."\" id=\"".$controlName."\" action=\"".$_SERVER['SCRIP
$output=$output."<table cellpadding=0 cellspacing=0 border=0 align=left>";
foreach ($this->arrColumns as $i => $value){
$output=$output."<tr>";
$output=$output."<td nowrap style=\"padding-bottom:3px
$output=$output."<td nowrap style=\"padding-left:5px;p
$output=$output."</td></tr
}
$output=$output."</table><
foreach ($this->arrHiddenFormVaria
$output=$output."<input type=\"hidden\" name=\"{$value[0]}\" id=\"{$value[0]}\" value=\"{$value[1]}\">";
}
$output=$output."<br /><input type=\"submit\" value=\"Save Changes\">";
$output=$output."</form>";
return $output;
} // end function editOutput
$objCurTable->strIdColumnV
if(strtolower($curAction==
$objCurTable->updateFromDa
foreach($objCurTable->arrC
echo "Test? - \$foreachCurColumn->strCur
}
}
echo $objCurTable->editOutput()
--------------------------
The following is output generated from the code above. Notice that during "Test2" the columns have values but during "Test" they do not:
Test? - $foreachCurColumn->strCurV
Test? - $foreachCurColumn->strCurV
Test? - $foreachCurColumn->strCurV
Test? - $foreachCurColumn->strCurV
Test? - $foreachCurColumn->strCurV
Test2? - $this->parentColumn->strCu
^^ The above line is repeated for each record in $result (in the controlOutput function)^^
Does anyone know why I am seeing this output and what changes to make so it see the strCurValues when it runs Test2 (in addition to "Test?")?
ASKER
Woops, i forgot to tell you where the parentColumn come from:
$this->objLink=&new clsLink($this);
function clsLink(&$inputParent,$inp utDisplayC olumn=null ,$inputKey Column=nul l, $inputTableName=null) {
$this->strDisplayColumn=$i nputDispla yColumn;
$this->strKeyColumn=$input KeyColumn;
$this->strTableName=$input TableName;
$this->parentColumn=$input Parent;
}
$this->objLink=&new clsLink($this);
function clsLink(&$inputParent,$inp
$this->strDisplayColumn=$i
$this->strKeyColumn=$input
$this->strTableName=$input
$this->parentColumn=$input
}
ASKER
Man you reply fast!
Try:
function clsLink(&$inputParent,$inp utDisplayC olumn=null ,$inputKey Column=nul l, $inputTableName=null) {
$this->strDisplayColumn=$i nputDispla yColumn;
$this->strKeyColumn=$input KeyColumn;
$this->strTableName=$input TableName;
$this->parentColumn=&$inpu tParent;
}
-r-
function clsLink(&$inputParent,$inp
$this->strDisplayColumn=$i
$this->strKeyColumn=$input
$this->strTableName=$input
$this->parentColumn=&$inpu
}
-r-
ASKER
Thanks for the replies Roonaan, I really appreciate your help today!
I changed the line that says "$this->parentColumn=$inpu tParent;" to "$this->parentColumn=&$inp utParent;"
but it still prints out "Test2? - $this->parentColumn->strCu rValue=" a number of times.
I changed the line that says "$this->parentColumn=$inpu
but it still prints out "Test2? - $this->parentColumn->strCu
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tried the "while" loop since i didn't know how those behaved differently before but I had no luck. I expect I am probably not giving you some critical piece of info so i uploaded my php files to https://filedb.experts-exchange.com/incoming/ee-stuff/1278-phpFiles.zip if you dont mind taking a look at the real thing (instead of the snippets on EE).
AddEditItem.php creates a table object (defined in clsTable.php) which has an array of column objects (defined in clsColumn.php) which contains a link object (defined in clsLink.php).
The values stored in the column object seem to persist but accessing it from the (child) link seems to be failing.
So i think the references in one direction and/or the other from the link are not working right.
What do you think?
AddEditItem.php creates a table object (defined in clsTable.php) which has an array of column objects (defined in clsColumn.php) which contains a link object (defined in clsLink.php).
The values stored in the column object seem to persist but accessing it from the (child) link seems to be failing.
So i think the references in one direction and/or the other from the link are not working right.
What do you think?
Final resort might be to implement an explicit reference:
$this->objLink->parentColu mn = &$this;
-r-
$this->objLink->parentColu
-r-
ASKER
Thanks for your help roonaan. I ended up just declaring another variable in the child class so that i wouldnt need a reference to the parent (even though it creates a duplicate).
-r-