0

How can i remove "dato" from $this->v ? And still have it in the $sql string.

OUTPUT (var_dump($this->v)):

array (size=4) ':kategori' => string 'Youstube' (length=8) ':link' => string 'http://urls' (length=11) ':navn' => string 'Rss feeds' (length=9) ':dato' => string 'NOW()' (length=5) 

OUTPUT (echo $sql)

UPDATE rss_kategori SET kategori = :kategori, link = :link, navn = :navn, dato = NOW()

CODE:

$classVars = get_class_vars(get_class($this)); $sql .= "UPDATE {$this->table} SET "; foreach ($classVars as $key => $value) { if ($key == 'v' || $key == 'db' || $key == 'id' || $key == 'table' || $key == 'table_id') { continue; } $keys = ""; $values = ""; $keys .= $key; if ($this->$key == 'NOW()') { $values .= $this->$key . ","; } else { $values .= ":" . $key . ","; } $this->v[":" . $key] = $this->$key; $sql .= "{$keys} = " . $values . " "; } $sql = substr($sql, 0, -2) . " WHERE {$this->table_id} = '{$this->id}'"; 
1

2 Answers 2

2

Please try this:

$key = ':dato'; $arr = $this->v; if (array_key_exists($key, $this->v) { unset($arr[$key]); $this->v = $arr; } 
Sign up to request clarification or add additional context in comments.

2 Comments

Can I check if the value NOW() exists in array?
Yes @nodde. if (in_array('NOW()', $this->v)) { echo "exists"; } else { // Blah blah }
1

Try using unset() function.

unset($this->v['dato']); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.