以下内容无效,并引发异常。
leaderboard_mode.php
<?php
class Leaderboard_model extends CI_Model {
function __construct()
{
parent::__construct();
}
public function get_by_role()
{
$query = $this->db->query->("SELECT b. * FROM (SELECT a. *, @rank := @rank + 1 rank FROM (SELECT MAX(score) AS max_score, user_id FROM highscore WHERE game_mode="bungkata" GROUP BY user_id ORDER BY max_score DESC)a, (SELECT @rank := 0)r)b LIMIT 10");
return $query->result();
}
}
这是例外:
遇到了未捕获的异常
类型:ParseError
消息:语法错误,意外的'(',期望的标识符(T_STRING)或变量(T_VARIABLE)或'{'或'$'
文件名:C:\ wamp \ www \ leaderboard \ application \ models \ Leaderboard_model.php
行号:12
回溯:
文件:C:\ wamp \ www \ leaderboard \ application \ controllers \ Leaderboard.php
线:9
功能:型号文件:C:\ wamp \ www \ leaderboard \ index.php
线:315
功能:require_once
答案 0 :(得分:0)
您只需要从
->
中删除query->
,就像$this->db->query()
,请参阅下面的更新代码
public function get_by_role()
{
$query = $this->db->query("SELECT b. * FROM (SELECT a. *, @rank := @rank + 1 rank FROM (SELECT MAX(score) AS max_score, user_id FROM highscore WHERE game_mode='bungkata' GROUP BY user_id ORDER BY max_score DESC)a, (SELECT @rank := 0)r)b LIMIT 10");
return $query->result();
}
答案 1 :(得分:0)
将此查询$query = $this->db->query->
更改为$query = $this->db->query("your sql query")
public function get_by_role()
{
$query = $this->db->query->("SELECT b. * FROM (SELECT a. *, @rank := @rank + 1 rank FROM (SELECT MAX(score) AS max_score, user_id FROM highscore WHERE game_mode="bungkata" GROUP BY user_id ORDER BY max_score DESC)a, (SELECT @rank := 0)r)b LIMIT 10");
return $query->result();
}
答案 2 :(得分:0)
leaderboard_model.php
<?php
class Leaderboard_model extends CI_Model {
function __construct()
{
parent::__construct();
}
public function get_by_role()
{
$query = $this->db->query("SELECT b. * FROM (SELECT a. *, @rank := @rank + 1 rank FROM (SELECT MAX(score) AS max_score, user_id FROM highscore WHERE game_mode=bungkata GROUP BY user_id ORDER BY max_score DESC)a, (SELECT @rank := 0)r)b LIMIT 10");
return $query->result();
}
}
controller:leaderboard.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Leaderboard extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model(array('Leaderboard_model'));
}
public function index(){
$data['datarank'] = $this->leaderboard_model->get_by_role();
$this->load->view('content_home', $data);
}
}
我的看法:content_home.php
<div id="main-description" class="col-md-6">
<div class="heading text-center">
<h1 class="text-white wow fadeInLeft"><strong>LEADERBOARD</strong></h1>
</div>
<div class="table-responsive text-white wow fadeInLeft">
<table id="authusertable" class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>Peringkat</th>
<th>Nama</th>
<th>Point</th>
</tr>
</thead>
<tbody>
<?php
$no = 0;
foreach ($datarank as $row):
$no++ ?>
<tr>
<td><?=$no?>
<td><?=$row->user_id?></td>
<td><?=$row->max_score?></td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
</tfoot>
</table>
</div>
</div>