Hello, I have two methods, one will fetch user data into an object property (an array) and the second will display that data as an html table.
The property is declared as:
var $Con_Array = array();
In the following snippet of code I have 3 methods displayed:
My problem:
If I call the method fetch_contacts(), it will populate the $this->Con_Array() with the results, this is good, I then call the method show_edit_table($um->Con_Array) and the data is displayed as an html table.
What I would like to do is make the method fetch_contacts() generic in nature, such as fetch_data() so that I can operate on various user tables depending on which object property and table name I call it with.
Typical code from php script:
// instantiate the object
$um = new User_Mst;
$db = new DB_Class;
some code here
call the object methods:
$db is an object and $uid came from the post.
fetch_contacts($db, $uid);
show_edit_table($um->Con_Array);
The above works perfectly well!
Based on the methods below, I want to call the fetch_data() function with the $um->Con_Array variable and have it populate the array with data, but it just ends up as an empty array.
function show_edit_table($data)
{
print "<table border=\"1\" cellspacing=\"2\" cellpadding=\"3\">\n";
$head = $data[0];
foreach($head as $key=>$value)
{
if ($key <> "USER_ID")
{
print "<th>";
echo $key;
print "</th>\n";
}
}
for($i = 0; $i < sizeof($data); $i++)
{
print "<tr bgColor='#EFEEC9' onMouseOver=\"this.bgColor='orange';\" onMouseOut=\"this.bgColor='#EFEEC9';\">\n";
foreach($data[$i] as $key=>$value)
{
if ($key <> "USER_ID")
{
print "<td nowrap=\"nowrap\">";
echo $value;
print "</td>\n";
}
}
print "</tr>\n";
}
print "</table>\n";
}// end function show_edit_table()
function fetch_data($db, &$thisarr, $table, $uid)
{
unset($thisarr);
$this->DB_Ref = &$db;
if ($conn = $this->DB_Ref->db_connect())
{// we made it in the db
$query = "SELECT * FROM $table WHERE USER_ID='$uid'";
$result = mysql_query($query);
for ($i = 0; $i < mysql_num_rows($result); $i++)
{
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$thisarr[$i] = $row;
}// end for i loop
$this->DB_Ref->db_close($conn);
unset($this->DB_Ref);
return TRUE;
}
else
{// we did not get a connection
return FALSE;
}
}// end function fetch_data()
function fetch_contacts($db, $uid)
{
unset($this->Con_Array);
$this->DB_Ref = &$db;
if ($conn = $this->DB_Ref->db_connect())
{// we made it in the db
$query = "SELECT CONTACT_ID, TYPE, VALUE FROM USER_CON WHERE USER_ID='$uid'";
$result = mysql_query($query);
for ($i = 0; $i < mysql_num_rows($result); $i++)
{
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$this->Con_Array[$i] = $row;
}// end for i loop
$this->DB_Ref->db_close($conn);
unset($this->DB_Ref);
return TRUE;
}// end conn if then
else
{
return FALSE;
}
}// end of function fetch_contacts()
I guess my question is, why can I pass the $um->Con_Array array to show_edti_table and have it display the data correctly, but I cannot pass $um->Con_Array to the fetch_data function and have it work?
Any thoughts would be appreciated
John