开发者

PHP MySQL query multiple rows

开发者 https://www.devze.com 2023-02-07 15:43 出处:网络
Hey guys, I seem to be having some problems with this code. What I am trying to do here is pull from my db of arti开发者_Python百科cles with specific dates. Then echo or print them out on the screen.

Hey guys, I seem to be having some problems with this code. What I am trying to do here is pull from my db of arti开发者_Python百科cles with specific dates. Then echo or print them out on the screen. Then later I will be limiting that number being printed to 15 or so per page, so there isn't necessarily 15 articles per day... This is what I have got started on, nothing too advanced, let alone working. I seem to be getting that warning below, and nothing is printed.

Im fairly new to php, but I know enough I guess to get by, barely...

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given

If someone could give me some pointers that would be great. Thanks a bunch!

    <?php

            define('INCLUDE_CHECK',true);

            require 'includes/connect.php'; 
            require 'includes/functions.php';


            $query = mysql_query("select * from post where date = curdate()");

            while($row = mysql_fetch_array($query))
            {
                echo"<div id='itemContainer'>
                        <div id='viewCounterContainer'><div id='views'></div>'".$row['postViews']."'</div>
                        <div id='commentCounterContainer'><div id='comment'></div>'".$row['postComCount']."'</div>  
                        <div id='clockContainer'><div id='clock'></div>'".$row['postTime']."'</div>
                            <div id='itemPostLarge'>            
                                <div id='imageContainerLarge'>
                                    <tag>'".$row['postMainTag']."'</tag>
                                </div>

                                <div id='textContainerLarge'>
<h2>'".$row['postTitle']."'</h2>
<br>'".$row['postShortCont']."'</div>
                    </div>
                    </div>";
            }
        ?>


The warning says that the supplied argument is not a ressource. As a successfull select-statement always returns a ressource(also if the result is empty), there has to be an error inside your query(if an error occurs mysql_query returns a boolean false).
What kind of error this is mysql_error() will tell you.


Try "IN"

$query = mysql_query("select * from post where id IN ('4','6','8') AND date = curdate()");


The problem with your code is that the Query is not completed.That means there is an error in your query.The easy way to find the error in a mysql query in php is to use mysqli_error($connection);for more information see php mannual http://in2.php.net/mysqli_error

I think the problem is that in $query you didn't escape the curdate() with quotes.Try this:

$query = mysql_query("select * from post where date = 'curdate()'");
mysqli_error($connection));

(I know this question is old and outdated but i 'am answering this for those who will see in future through search)

0

精彩评论

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