Credits_model.php
PHP复制代码
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Credits_model extends CI_Model {
function __construct ()
{
parent ::__construct ();
}
function GetInit ($username)
{
$data = array(
'user_name' => $username ,
'user_credits' => '5'
);
$query=$this->db->query("SELECT * FROM `pre_credits` WHERE `user_name` LIKE '$username' LIMIT 0, 30 ");
if($query->num_rows() > 0)
{
return 1;
}
$this->db->insert('pre_credits', $data);
return -1;
}
function GetCredit ($username)
{
$query=$this->db->query("SELECT * FROM `pre_credits` WHERE `user_name` LIKE '$username' LIMIT 0, 30 ");
if($query->num_rows() > 0)
{
return $query;
}
return -1;
}
}
复制代码
Credits.php(Contrller)
PHP复制代码
public function index()
{
$this->load->library('session');
$data['user_name']=$this->session->userdata('user_name');
if(@$data['user_name']!=null){
$this->load->model('Credits_model');
$this->load->database();
$tmp[0]=$this->Credits_model->GetInit($data['user_name']);
$tmp[1]=$this->Credits_model->GetCredit($data['user_name']);
$data['title']=$this->data_title_index;
$data['board_name']=$this->data_title_real;
$data['description']=$this->data_description;
$data['more']=$this->data_more;
$data['reload']=$tmp[0];
$data['credits']=$tmp[1];
$this->load->view('header_view',$data);
$this->load->view('credits_view',$data);
$this->load->view('footer_view');
}
}
复制代码
BUG::
SQL 查询结果主机: localhost
资料库: test
产生日期: 2012 年 06 月 07 日 15:52
产生者: phpMyAdmin 3.4.9 / MySQL 5.5.20
SQL 查询: SELECT * FROM `pre_credits` LIMIT 0, 30 ;
行数: 4 user_name user_credits
贝壳2 99999
0 5
jmxx1749 5
0 5
|