即使没有在php中询问,所有数据都是从mysql数据库中获取的

时间:2017-03-13 11:59:08

标签: php html mysql get

MySQL表 - 帖子,我正在使用以下查询......

SELECT who, votes, content, time FROM posts WHERE category = 10 ORDER BY time DESC LIMIT 10;

以下php代码似乎有效,但无论选择何种选项都会显示所有数据...

<?php
            function Qfeed($cat){
                include("config.php");
                if($cat = "1"){
                    $query = "SELECT who, votes, content, time FROM posts ORDER BY time DESC LIMIT 10";
                }elseif($cat = "2"){
                    $query = "SELECT who, votes, content, time FROM posts WHERE votes > 100 ORDER BY votes DESC LIMIT 10";
                }elseif($cat = "3"){
                    $query = "SELECT who, votes, content, time FROM posts WHERE DESC LIMIT 10";
                }else{
                    $query = "SELECT who, votes, content, time FROM posts WHERE category = '$cat' ORDER BY time DESC LIMIT 10";
                }
                $result = mysqli_query($dbc, $query) or die('Error querying database!');
                if ($result->num_rows > 0) {
                    while($row = $result->fetch_assoc()) {
                            echo "<article id='qpost'><section class='pvotes'><p>" .$row["votes"]. "</p></section><section class='ptitle_whoasked_time'><p class='ptitle'>" .$row["content"]. "</p><p class='pwhoasked_time'>POSTED BY " .$row["who"]. " [" .$row["time"]. "]</p></section></article>";
                    }
                }else {
                    echo "0 results";
                }
                mysqli_close($dbc);
            }

            if(isset($_GET["cat"])) {
                $cat = $_GET["cat"];
                Qfeed($cat);
            }
        ?>

问题:即使我通过,通过GET说1,我也没有得到预期的结果。

0 个答案:

没有答案