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
どんな助けでも大歓迎です