0

MySQL table- posts and i am using the following query...

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

The following php code seems to work but displays all the data no matter what option is chosen...

<?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);
            }
        ?>

Problem: Even when I pass, say 1 through GET, i don't get the expected results.

0 Answers0