doubi8512 2014-12-24 23:35 采纳率: 0%
浏览 52

为什么php if else不能使用JSON数据

I am fetching information from my database as JSON array.The problem is i am unable to use this data to compare using if else or assign to a PHP variable.

query:

$query="select * from dmo";

$result = $mysqli->query($query) or die($mysqli->error.__LINE__);

$arr = array();
if($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        $arr[] = $row;  
    }
}
# JSON-encode the response
$json_response = json_encode($arr);

// # Return the response
echo $json_response;

Data:

<tr ng-repeat="data in filtered = (list | filter:search | orderBy : predicate :reverse) | startFrom:(currentPage-1)*entryLimit | limitTo:entryLimit">
                    <td>{{data.tran_id}}</td>
                    <td>{{data.tran_type}}</td>
                    <td>{{data.sender}}</td>
                    <td>{{data.amount}}</td>
                    <td>{{data.fee}}</td>
                    <td>{{data.date}}</td>
                    <td>
                    <?php $s="{{data.status}}"; if ($s == "0")
                    echo"Pending"; 
                    else if ($s == "1") echo"Completed"; 
                    ?>
                    </td>


                </tr>
  • 写回答

1条回答 默认 最新

  • dongyi0210 2014-12-25 00:02
    关注

    You haven't told us anything about how your templating engine works or which one it is, but it seems clear enough from your problem that it's not preprocessed PHP. You can't just mix technologies like that and expect it to work.

    Read up about how PHP is invoked, what its result is, how that result is transferred to a browser and how that browser interprets what it's received; you'll see that what you wrote doesn't make any sense.

    More than likely, the templating engine you're using will have its own conditional syntax. For example, in AngularJS you would write:

    {{data.status == 1 ? "Too young" : "Old enough"}}
    

    Have a good read through the documentation for the technologies that you use.

    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?