这是我第一次使用 MVC,并且我已经阅读了代码点火器的文档。但我似乎无法正确查询:
$score = $_POST['time'];
$sql = "SELECT COUNT(score) as c FROM highscores WHERE score < '$score' ORDER BY score ASC LIMIT 10";
$result = mysqli_query($con, $sql);
$count = mysqli_fetch_object($result)->c;
if(!is_null($count) && $count < 10) {
echo 1;
}
然后是我的代码点火器版本:
public function insert_highscore($score) {
$this->db->select('COUNT(score) as c')->from('highscores')->where('score < ' . $score);
$query = $this->db->get();
$count = $query->c;
if(!is_null($count) && $count < 10) {
echo 1;
}
return $count;
}
我这样称呼那个函数:
public function index()
{
$this->load->view('header');
$this->load->model('highscores_model');
$data = $this->highscores_model->get_highscores();
$this->highscores_model->insert_highscore("00:00:01.11");
foreach($data as $highscore){
echo $highscore['name'];
echo $highscore['score'];
}
$this->load->view('footer');
}
并得到这个错误
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':00:01.11' at line 3
SELECT COUNT(score) as c FROM (`highscores`) WHERE `score` < 00:00:01.11
Filename: /storage/websites/cambist_app/codeigniter/models/highscores_model.php
Line Number: 15
非常感谢任何帮助