开发者

My while loop won't echo out data from my database

开发者 https://www.devze.com 2023-02-26 14:23 出处:网络
Right, so I\'m trying to execute a news function, and I\'ve coded it the same way I always do, but some some reason it won\'t work as the data is not showing, although my mysql_num_rows function is de

Right, so I'm trying to execute a news function, and I've coded it the same way I always do, but some some reason it won't work as the data is not showing, although my mysql_num_rows function is detecting the data in the database.

require('php/connect.php');

$query = mysql_query("SELECT * FROM news ORDER BY id DESC");

$numrows = mysql_num_rows($query);

    if($numrows=!0)
    {

        while ($row = mysql_fetch_assoc($query));
        {

        $body = $row['body'];
        $date = $row['date'];

        echo "Posted on: "strtotime($date)" |";
        echo "<hr width='20%' align='left'";
        echo "$body <br /> <hr width='100%' />";

        }

  开发者_运维百科  }
    else    
        die("There are no news posts to show.")

If anyone could tell me what is going wrong in my code, it would be very much appreciated.


use this if($numrows) instead of if($numrows=!0)

AND use

echo "Posted on: ".strtotime($date)." |";

instead of using

echo "Posted on: "strtotime($date)" |";

Ad there is one more mistakes in

echo "<hr width='20%' align='left' />";   // closing tag for <hr>
echo "$body <br /> <hr width='100%' />";  


Change it

if($numrows=!0)

To

if($numrows != 0)


Not about your problem, but if($numrows=!0) will be ALWAYS true. Use if($numrows!=0)


One thing is for sure, it's the $numrows thing you added to the query. That or there is nothing to echo out. Try the query without checking if it returned anything or not.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号