I've got a home-grown LAMP app that uses the same HTML code for the "Modify record" and "New record" pages based on whether it is passed a blank record or a non-blank record. Currently, I'm creating the blank record by selecting a single record from the MySQL table and manually setting each field (by name) to NULL. There's got to be a better way to do this, but the search terms to find what I need are just too darn generic. I've looked at using something like mysql_fetch_array or get_class_vars, but I just can't get them to work. Here's what I'm trying to replace with something a bit less manual:
// Select a row, any row... (using CodeIgniter)
$q = $this->db->get($this->config->item('db'),1);
// For each ... um ... one ... row, add it to $data
foreach ($q->result() as $row) {
$data[] = $row;
}
// set each **KNOWN** field to NULL
$data[0]->column1 = NULL;
$data[0]->column2 = NULL;
...
I know it's a dirty hack, but it works. What's the "right" way to do this?