我的php有问题.我一直在使用codeigniter,以下代码返回给我这个错误消息:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: item
Filename: views/banner.php
Line Number: 37
Run Code Online (Sandbox Code Playgroud)
我的控制器如下:
public function __construct()
{
parent::__construct();
$this->auth->check();
$this->load->database();
$this->load->helper('url');
$this->load->model('banner_model');
}
public function index()
{
$dados['banner'] = $this->banner_model->recuperar_todos_banners();
$this->load_view("banner", $dados);
}
Run Code Online (Sandbox Code Playgroud)
我的看法:
<? foreach ($banner as $item):?>
<tr>
<td><?=$item->chave?></td>
<td><?=$item->imagem?></td>
<td><?=$item->descricao?></td>
<td><?=$item->link?></td>
<td>
<button type="button" class="btn btn-danger btn-xs">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
<? endforeach; ?>
Run Code Online (Sandbox Code Playgroud)
我使用var_dump测试了两个变量.此代码的目的是访问MySQL数据库并将结果存储在数组中.$ banner变量工作正常,所有数据都在那里,因此每个位置都被对象占用,每个对象都是一个表行.
我知道之前在StackOverflow上已经问过这个问题,但我仍然无法弄清楚到底发生了什么.
我做了一个简单的Java程序,它使用Thread对象在JPanel周围移动一个方块.方块移动到随机位置,更改其颜色,JPanel更改其背景颜色.然后线程休眠1000毫秒.但后来又添加了一行代码,为JLabel增加了+1,并且方块停止了移动(当分数正在工作并添加+1时).
这是代码:
@Override
public void run() {
Random random = new Random();
int width = 0;
int height = 0;
while(true) {
width = random.nextInt(area.getSize().width) + 1;
height = random.nextInt(area.getSize().height) + 1;
width -= ((width - 45) > 0) ? 45 : 0;
height -= ((height - 45) > 0) ? 45 : 0;
this.square.setLocation(width, height);
this.square.setIcon(new ImageIcon(getClass().getResource("/img/square" + (random.nextInt(4) + 1) + ".png")));
this.area.setBackground(new Color(random.nextInt(255) + 1, random.nextInt(255) + 1, random.nextInt(255) + 1));
//The following line works, but the …Run Code Online (Sandbox Code Playgroud)