0

如果该值设置为 null 并且您单击它将更新为一个的链接,我目前已经实现了一个点击计数器。但是当它第二次被点击时它不会更新它保持原样。

public function getUpdateClick($Id) {
    $Id=DB::escape_string($Id);
    $i=1;
    $click=0;
    $click=$click+$i;

    $updatesArray=array('clicks'=>$click);// the column which is going to be updated

    $this->setTable('pages'); //setting the table name

    $where="id=$Id";

    $result=$this->update($updatesArray,$where); // query executed
}
4

3 回答 3

0

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
于 2013-03-31T08:48:51.440 回答
0
$click=0;
$click=$click+$i;

删除第一行并将 $click 的值存储为会话变量或将其存储在数据库中。

于 2013-03-31T08:01:26.733 回答
0

每次调用该函数时,$click 的值都会设置为 0,然后在下一条语句中设置为 1。如果您希望该值保持不变,您应该在表中使用一个属性并在每次单击时递增它。

于 2013-03-31T09:10:38.153 回答