2016-02-29 33 views
0
<table> 
<thead> 
<tr> 
<th>model</th> 
<th>a</th> 
<th>jumlah</th> 
</tr> 

    </thead> 
    <?php foreach((array)$query as $row): 
         if ($row->model='10') { 
          $jumlah=$row->a-10; 
         }else{ 
          $jumlah=$row->a-5; 
         };?> 
    <td><?php echo $row->model ?></td> 
    <td><?php echo $row->a ?></td> 
    <td><?php echo $jumlah ?></td> 

应该导致这样为什么在我的代码中如果还有其他重写值?

enter image description here

但为什么是这样的结果呢?

enter image description here

为什么coloumn模型超越控制10个数据? 如何解决?

+3

单个'='受让人,''==检查是否相等 – baao

+0

'='是赋值,你需要''==比较操作 –

+1

不同的语言,但完全相同的概念:http://stackoverflow.com/questions/2063480/the-3-different-equals –

回答

2

您使用赋值运算符(=)不是等号(= =)。改变这一行:

if ($row->model = '10') { 

这样:

if ($row->model == '10') { 

或本:

if ($row->model == 10) { 

在第一种情况下,你告诉编译器来存储值10 进入变量$row->model

在我们正在检查,以查看是否的 $row->model的值等于10。

字符串值。在我们正在检查,以查看是否的 $row->model的值等于所述第三壳体的第二壳体数值为10.

我的猜测是这样的,你可能想使用第三种情况,除非数字在数据库中存储为文本值。

1

出好心情的今天:

<?php foreach((array)$query as $row): 
        if ($row->model=='10') { # <- added double = sign 
         $jumlah=$row->a-10; 
        }else{ 
         $jumlah=$row->a-5; 
        };?> 
相关问题