In your function, you should first check if there is a value for clicks
on the pages
tables for the specific page (where id=$id
). If there isn't, then you can give clicks=1
, otherwise get that value and add 1.
But here's how I'd do it: I'd edit the table by disabling ALLOW NULL in the clicks
column, so that by default, when a new page is created, it's default value is 0. Then I'd use the code below:
public function getUpdateClick($Id){
$Id=DB::escape_string($Id);
//You can edit the 3 lines below to check the database
// in pages table in clicks column where id=$Id in your custom way
$fetching sql_result = mysql_query('SELECT * FROM pages where id=$Id')
$row = mysql_fetch_assoc($fetching sql_result);
$current_number_of_clicks = $row['clicks'];
$click= $current_number_of_clicks;
$click=$click+1;
$updatesArray=array('clicks'=>$click);// the column which is going to be updated
$this->setTable('pages'); //setting the table name
$set="click=click+1"; // column and value
$where="id=$Id"; //
$result=$this->update($updatesArray,$where); // query executed
}
} // I assume this closes your class