Ryahn
Ryahn

Reputation: 557

Unable to fetch data equal to 0

I have a small database that will show data being updated as 0 and not as 1. When I try to run the following sql query

Database PHP // Connect To DB $hostname="localhost"; $database="xxxx"; $username="xxxxx"; $password="xxxxx";

@$conn = mysqli_connect($hostname, $username, $password)
        or die("Could not connect to server " . mysql_error()); 
    mysqli_select_db($conn, $database)
        or die("Error: Could not connect to the database: " . mysql_error());

    /*Check for Connection*/
    if(mysqli_connect_errno()){
        // Display Error message if fails
        echo 'Error, could not connect to the database please try again again.';
    exit();
    }

$query = 'SELECT * FROM mods ORDER BY id where updated="0"';
$result = mysqli_query($conn, $query);
@$num_results = mysqli_num_rows($result);

I have tried wrapping and not wrapping the 0 in '' and "".

Currently it just loads the HTML table without data. If I remove the where statement, it pulls fine.

HTML PHP

                             for($i=0; $i<$num_results; $i++) {
                                    $row = mysqli_fetch_assoc($result);

                                    ?>


                                        <tr>



                                <td style=""><?php print $row['mod_name']; ?></td>
                                <td style=""><div id"tdcenter" style="width: 44px;white-space:nowrap;overflow: hidden;text-overflow: ellipsis;text-align:center;"><?php print $row['mod_version']; ?></div></td>
                                <td style=""><?php print $row['time']; ?></td>
                            </tr>
<?php 
// end loop
} 
?>

Upvotes: 1

Views: 70

Answers (2)

Death-is-the-real-truth
Death-is-the-real-truth

Reputation: 72269

Please try these and check which one works for you:-

  1. As @BigRabbit says :- $query = "SELECT * FROM mods ORDER BY id where updated='0'";

  2. create a variable $update = 0; and now append it to your query $query = "SELECT * FROM mods ORDER BY id where updated=".$update;

  3. Another attempt is swapping ORDERBY and WHERE clause.

Upvotes: 1

BRBT
BRBT

Reputation: 1487

The syntax on your query is wrong try this:

$query = "SELECT * FROM mods ORDER BY id where updated='0'";

Upvotes: 1

Related Questions