Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 只获取今天的帖子?_Mysql_Php - Fatal编程技术网

Mysql 只获取今天的帖子?

Mysql 只获取今天的帖子?,mysql,php,Mysql,Php,我需要有一个功能,将回声的帖子已经张贴了今天 从00点到23点59分。我已经创建了一个函数,但它没有给出我需要的结果 以下是我的功能: function todayNews() { $id = mysql_real_escape_string ($id); $sql = 'SELECT * FROM wp_posts WHERE post_status = "publish" AND post_date = CURRENT_DATE ORDER BY post_date DE

我需要有一个功能,将回声的帖子已经张贴了今天

从00点到23点59分。我已经创建了一个函数,但它没有给出我需要的结果 以下是我的功能:

function todayNews() {
    $id = mysql_real_escape_string ($id);
    $sql = 'SELECT * FROM wp_posts WHERE  post_status = "publish" AND post_date = CURRENT_DATE  ORDER BY post_date DESC LIMIT 15';
    $res = mysql_query($sql) or die (mysql_error());

if (mysql_num_rows($res) !=0):
    while ($row = mysql_fetch_assoc($res)) {

    $title = ($row['post_title']);

    $old_date = $row['post_date'];             // returns Saturday, January 30 10 02:06:34
    $old_date_timestamp = strtotime($old_date);
    $new_date = date('H:i', $old_date_timestamp);

    $mycontent = ($row['post_content']);
    $mycontent = strip_tags($mycontent);
    $mycontent = substr($mycontent,0,350);
    $mycontent = preg_replace("/\[caption.*\[\/caption\]/", '', $mycontent); 

    $first_img = '';
    $my1content = $row['post_content'];
    $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $my1content, $matches); 
    $first_img = $matches [1] [0];
    if(empty($first_img)){ //Defines a default image
    $first_img = "/img/default.png";
    }

    echo '


    <ul class="li-sub">
                <li>
'.$title.'
</li>

        </ul>

    ';  
}
    else:
        echo 'There are no posts for today !';
    endif;

} // end  
functiontodaynews(){
$id=mysql\u real\u escape\u字符串($id);
$sql='SELECT*FROM wp_posts,其中post_status=“publish”和post_date=当前_date ORDER BY post_date DESC LIMIT 15';
$res=mysql\u query($sql)或die(mysql\u error());
如果(mysql_num_rows($res)!=0):
while($row=mysql\u fetch\u assoc($res)){
$title=($row['post_title']);
$old_date=$row['post_date'];//返回1月30日星期六02:06:34
$old\u date\u timestamp=strottime($old\u date);
$new_date=日期('H:i',$old_date_timestamp);
$mycontent=($row['post_content']);
$mycontent=strip_标签($mycontent);
$mycontent=substr($mycontent,0350);
$mycontent=preg\u replace(“/\[caption.*\[\/caption\]/”,“”,$mycontent);
$first_img='';
$my1content=$row['post_content'];
$output=preg_match_all('//i',$my1content,$matches);
$first_img=$matches[1][0];
if(empty($first_img)){//定义默认图像
$first_img=“/img/default.png”;
}
回声'
  • “.$title。”
'; } 其他: echo“今天没有帖子!”; endif; }//结束
谢谢大家!

编辑:
发布日期的格式为:Y-m-d H:i

如果您将发布日期(日期时间)与当前日期(日期时间)进行比较,则不会给出任何结果

您可以尝试以下SQL语句

$sql = 'SELECT * FROM wp_posts WHERE  post_status = "publish" AND DATE(post_date) = CURRENT_DATE  ORDER BY post_date DESC LIMIT 15';

这将在与当前日期进行比较之前将post_日期转换为only date。

您得到了什么,您想得到什么?表中的
post_date
是什么类型的列?其中的数据是如何存储的?您好,我已经编辑了关于post_date格式的帖子!
1月30日,星期六…
不是MySQL日期格式。我如果这是您从表中的日期字段中得到的字符串,那么它不是日期/日期时间字段,无法与读取的日期值进行比较。