This is a INSERT function. It's working... I just pulled out the function from the class, atm to try it out. And improve. I think the code is a bit messy, And I am pretty sure I can improve the code, less code, for example.. Any ideas?
$data['test'] = array('username' => 'john',
'password' => 'hello',
'userlevel' => '__d');
$table = 'users';
$numItems = count($data['test']);
$i = 0;
$sql = "INSERT INTO " . $table . "(". implode(", ", array_keys($data['test'])) .")";
$sql .= " VALUES (";
$i = 0;
foreach ($data['test'] as $value) {
if ($i+1 == $numItems and $value == '__d') {
$sql .= "" . 'NOW()' . ")";
} else if ($i+1 == $numItems) {
$sql .= "'" . $value . "')";
} else if ($value == '__d') {
$sql .= "" . 'NOW()' . ", ";
} else {
$sql .= "'" . $value . "', ";
}
$i++;
}
echo $sql;
foreach
why the comparation of$i + 1 == $numItems
if you end up doing the same, be that comparation true or false? \$\endgroup\$