I want to create a global function insert. i have a code like this
function insert_data($table, $field = array(), $data = array())
{
$sql = "INSERT INTO ".$table." (";
$i = 0;
for($f=0; $f < count($field); $f++)
{
$sql .= ++$i === count($field) ? $field[$f] : $field[$f].", ";
}
$sql .= ") VALUES (";
for($d=0; $d < count($data); $d++)
{
$sql .= end($data) === $data[$d] ? (is_string($data[$d]) ? $this->db->escape($data[$d]) : (is_null($data[$d]) ? "NULL" : $data[$d])) : (is_string($data[$d]) ? $this->db->escape($data[$d])."," : (is_null($data[$d]) ? "NULL," : $data[$d].","));
}
$sql .= ")";
$qry = $this->db->query($sql);
return $this->db->affected_rows();
}
it's work fine for me, but i want the parameters just the name of table and data with index is name of field. how to create like that? thanks for the answer