Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.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/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
PHP无法获取SQL日期字段_Php_Mysql_Sql_Date - Fatal编程技术网

PHP无法获取SQL日期字段

PHP无法获取SQL日期字段,php,mysql,sql,date,Php,Mysql,Sql,Date,我正在建立一个列出事件的网站(我的第一个!), 必要时嵌套在年和月标题内。 我知道有点乱,但是嘿 我在某个地方出错,MySQL数据库中的日期字段没有正确传递。 所以它只是默认为01-01-1970 <?php $query = 'SELECT * FROM events'; $result = mysql_query( $query ); $current_month = 'no_month_given'; $current_year = 'no_year

我正在建立一个列出事件的网站(我的第一个!), 必要时嵌套在年和月标题内。 我知道有点乱,但是嘿

我在某个地方出错,MySQL数据库中的日期字段没有正确传递。 所以它只是默认为01-01-1970

<?php

    $query = 'SELECT * FROM events';
    $result = mysql_query( $query );
    $current_month = 'no_month_given';
    $current_year = 'no_year_given';
    $year_count = 0;
    $month_count = 0;
    $year = date("Y", strtotime($row['event_startdate']));
    $month = date("M", strtotime($row['event_startdate']));
    $startday = date("d", strtotime($row['event_startdate']));
    $endday = date("d", strtotime($row['event_enddate']));

    while($row = mysql_fetch_array($result))
        {

    /* YEAR */

            if($current_year != $year) 
                {
                    $current_year = $year;
                    echo "  <div id=\"year\">
                    <p class=\"vert\">" .$current_year. "</p>";
                    $year_count++;
                }

    /* MONTH */

        if($current_month != $month) 
                {
                    $current_month = $month;
                    echo '<div id="month"><h1>' . $current_month . '</h1>';
                    $month_count++;
                }

    /* EVENT DETAILS */

}

将这些行放入while循环中:

$year = date("Y", strtotime($row['event_startdate']));
$month = date("M", strtotime($row['event_startdate']));
$startday = date("d", strtotime($row['event_startdate']));
$endday = date("d", strtotime($row['event_enddate']));

由于$row之前未定义,因此无法在循环外使用$row变量。

在设置$row之前,请打开错误报告。此外,我没有看到任何
mysql\u connect()
mysql\u select\u db()
,因此这也可能是第二个问题