Here's my class and I'm wishing to add a whole new table (from sql) to this class.
I changed a select box on an edit page and it now references a different table.
<tr><td>Trainer Group</td><td><?php sbox('name', sql::one_column_array("select substring(name, 1, 27) from et.do.trainer_group")); ?></td></tr>
my old select box referenced et.AS.trainer
and so now the save logic is broken.
I wish to add a bunch of new class variables for all the fields in the new table which i know i can accomplish by adding to the static variables below.
class Trainer
{
public $id,
$first,
$last,
$trainer_address1,
$trainer_address2,
$CITY,
$STATE,
$trainer_zip,
$trainer_phone,
$trainer_fax,
$trainer_cell,
$website_trainer_id,
$trainer_email,
$trainer_group,
$lat,
$long,
$group_name,
$name,
$inactive,
$group_id;
public function __construct($array)
{
foreach ($array as $k => $v)
{
if (property_exists($this, $k))
$this->{$k} = strtoupper($v);
}
}
public static function db_trainer ($id)
{
$results = sql::clean_row('Select * from et.AS.trainer where id ='. $id);
return new \AS\Trainer($results);
}
public function save()
{
if(!$this->id)
$this->id = '';
sql::merge('et', 'AS', 'trainer', array('id'), get_object_vars($this));
}
public function update($array)
{
foreach ($array as $k=>$v)
{
if (property_exists($this, $k) && $v != $this->{$k})
{
$this->{$k} = strtoupper($v);
}
}
$this->save();
}
In my class i can not get the new select box to save.. in the db_trainer function i added a sql left outer join to include the new table and now i'm able to create new static variables from that trainer_group
table like so:
Select * from et.AS.trainer a left outer join event.dbo.trainer_group b on a.group_id = b.id where a.id ='. $id
my problem is obviously in the save()
or the update()
How can i use my save logic in the merge
so when someone uses the select box it starts sticking?
I'm imagining since this problem is on my edit page i'll need to add some logic into the update function by editing the foreach loop..?
Any help would be greatly appreciated.