public function load_top_players() {
$this->load->lib(array('rank_db', 'db'), array(HOST, USER, PASS,CHARACTERS));
$query = $this->rank_db->query('SELECT name, access FROM users ORDER BY access DESC LIMIT 5');
while($row = $query->fetch()) {
$this->rank[] = array(
'name' => htmlspecialchars($row['name']),
'level' => (int)$row['access']
);
}
return $this->rank;
}
<?php
$rank = load::get('website');
$i = 1;
foreach ($rank as $pos => $player) {
$first = (in_array($i, array(1))) ? '' : '';
$second = (in_array($i, array(2))) ? '' : '';
echo '<tr style="'.$first.' '.$second.' '.$third.'">
<td >'.$i.'</td>
<td>'.$player['name'].'</td>
<td>'.$player['access'].'</td>
</tr>';
$i++;
}
?>
它显示一个空白页面,没有任何错误!
答案 0 :(得分:1)
<强> helper.website.php 强>
public function getOnlineCount(){
$this->load->lib(array('rank_db', 'db'), array(HOST, USER, PASS, CHARACTERS));
return $this->registry->rank_db->snumrows('SELECT count(name) as count from users where status <> -1 AND sub_status>= 1');
}
并在 view.header.php <?php echo load::get('website')->getOnlineCount() ; ?>
中完美无缺!如何将其转换为我的查询
答案 1 :(得分:0)
它显示空白页面,因为您没有将任何数据传递到您的视图文件。要在视图文件中获取数据,必须使用某些数据从控制器加载视图。语法是 -
CC=gcc
CFLAGS=-I
AIM = server
HEADS = ../common/common.h
OBJS = comfunc.o
MOBJ = server.o
MISCS = server.cfg
SRCS = ${OBJS:.o=.c} ${MOBJ:.o=.c}
#targets
all: $(AIM)
server:server.o $(OBJS) $(MOBJ)
$(CC) $(LDFLAGS) $(CFLAGS) -o server server.o $(OBJS) $(LIBS)
#dependency
$(OBJS):../common/common.h
comfunc.o: ../common/common.h
然后从您的视图文件中访问它。