我正在创建一个网站来创建一个简短的网址。我在计算短网址的点击数时遇到了问题。我可以从数据库获取简短的URL并重定向到特定的网站。一旦其重定向特定网站的短网址点击次数将增加+1。但它并没有增加。最后一天,我的自我尝试,但我不能得到结果。使用codeigniter来计算短网址的点击次数
这是我的控制器编码..
class Go extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->model('Select_model');
}
public function index(){
$url_code = $this->uri->segment(1);
// redirect the short url
$query = $this->Select_model->selectShortUrl($url_code);
// update clicks for short url
$update = $this->Select_model->updateShortUrl($url_code);
}
}
这是我的模型编码..
// redirect the short url
public function selectShortUrl($shorturl){
$cx=$this->db->select('*')
->from('url i')
->where('i.shorturl',$shorturl)
->get();
if ($cx->num_rows() == 1) {
foreach ($cx->result() as $row) {
$url_address = $row->fullurl;
}
redirect (prep_url($url_address));
}
else{
redirect(base_url());
}
}
// update clicks for short url
public function updateShortUrl($shorturl){
$cx=$this->db->set('clicx','`clicx`+1')
->where('shorturl',$shorturl)
->update('url');
return $cx->result();
}
当你重定向URL那段时间更新计数,我认为。你的问题是更新计数后重定向URL,所以计数不会更新。 –
@HothiJimit感谢您的评论...你知道如何解决这个问题。 – pixel