Проверка соответствия строки php не дает ожидаемого результата - PullRequest
0 голосов
/ 19 мая 2018

Я пытаюсь использовать php, чтобы проверить, совпадают ли две строки, если они есть, то сделать что-то.

Но мой оператор if продолжает возвращать false, даже если они совпадают.

Посмотрите на мой файл VIEW.перед оператором if я даже использовал echo, чтобы посмотреть, что они из себя представляют.

Чего мне не хватает?Это как-то связано с angularjs ???

Кстати, echo $type . " " . '{{ post.postType }}'; на самом деле приводит к этому:

<!-- The View -->
<body ng-app"myApp">
<div class="container testing" ng-controller="feedControl">
    <table>
      <tr ng-repeat="post in posts">
        <td style="padding:15px">{{ post.postType }}</td>
        <td style="padding:15px">{{ post.postTitle }}</td>
        <td style="padding:15px">{{ post.postDescription }}</td>
        <td style="padding:15px">{{ post.postDate }}</td>
        <td style="padding:15px">
        <?php
        $type = '{{ post.postType }}';

        echo $type . " " . '{{ post.postType }}';

        if($type == 'image'){
                 echo $type . " " . '{{ post.postType }}';
        };
        ?>
    </td>
      </tr>
    </table>
    <br>
</div>
</body>




<!-- feed.php -->
<?php

    include 'db.php';

    connection();

    $sql = "SELECT * FROM feed ORDER BY time DESC";
    $result = $conn->query($sql);

    $outp = "";
    while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
        if ($outp != "") {$outp .= ",";}

        $source = "";
        if($rs["post_type"] == "video"){
            $source = str_replace('<iframe width="560" height="315" src="', '', $rs["src"]);
            $source = str_replace('" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>', '', $source);
        }
        if($rs["post_type"] == "music"){
            $source = str_replace('<iframe width="100%" height="300" scrolling="no" frameborder="no" allow="autoplay" src="', '', $rs["src"]);
            $source = str_replace('"></iframe>', '', $source);
        }
        if($rs["post_type"] == "image"){
            $source = $rs["src"];
        }


        $outp .= '{"postType":"'  . $rs["post_type"] . '",';
        $outp .= '"postDate":"'   . $rs["time"]        . '",';
        $outp .= '"postTitle":"'   . $rs["post_title"]        . '",';
        $outp .= '"src":"'   . $source        . '",';
        $outp .= '"postDescription":"'. $rs["post_description"]     . '"}';
    }
    $outp ='{"records":['.$outp.']}';


    connectionClose();

    echo($outp);

?>




<!-- module -->
var app = angular.module("myApp", ["ngRoute"]);

<!-- controller -->
app.controller('feedControl', function($scope, $http) {
    $http.get("pages/db_section/feed.php")
    .then(function (response) {
        $scope.posts = response.data.records;
    });
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...