SQL将在7天后显示数据

时间:2012-01-06 17:27:42

标签: php mysql date

我之前打开了一个类似的线程但没有成功。但它帮助我改进了我的代码,但我还没有达到目标。我想要做的是在会议开始后7天在我的网站上显示一组会议记录。对此的sql语句如下:

i have taken some of Ashley Banks code and inserted into mine without any success. I am not getting any errors but I am also not getting any data to show up. my code is as follows::

    <?php
$id = $_GET['meeting_id'];
$from = date( 'Y-m-d', strtotime( $row['date_update'] . '-7 days' ) ); 

$result = mysql_query('SELECT * FROM Meetings LEFT JOIN Minutes ON Meetings.meeting_id = Minutes.meeting_id 

INNER JOIN Rooms ON Meetings.meeting_id = Rooms.meeting_id 

WHERE  Rooms.date >= "' . $from . '" AND Rooms.date <= NOW() AND Minutes.approval = "approved" AND Meetings.meeting_id = "$id"')

or die(mysql_error());

if (mysql_num_rows($result) == 0) {
       echo '<h3>There Arent Any Minutes For This Meeting Yet</h3>';
    } else {

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

        echo "<tr>";
        echo "<td><br/>" .'Title: '. $info['title']." </td>";
        echo "<td><br/><br/>" .'Subject: '. $info['subject']. "</td>";
        echo "<td><br/><br/>" .'Next Subject: '. $info['next_subject']."</td>";

        echo '<br/><br/><a href="attendees.php?meeting_id=' . $info['meeting_id'] . '" target="_blank">Attendees</a>';
        echo '&nbsp;|&nbsp;<a href="apologies.php?meeting_id=' . $info['meeting_id'] . '" target="_blank">Apologies</a>';



        }
    }
echo "</tr>";
echo "</table>";


?>

我的表格和字段:

会议:meeting_id,职称,主席,秘书,tof,出现,行动

房间:room_id,房间,日期(这是在varchar字段中,我知道它的格式不正确,但它是这样的),time,meeting_id。

分钟:minute_id,subject,next_subject,approval,meeting_id

它没有显示任何数据。它只是回应我的信息,“这次会议还没有任何会议记录”

我的Rooms表中日期字段的数据类型是date。

任何帮助人员?

2 个答案:

答案 0 :(得分:0)

也许使用BETWEEN?

$enddate = date('Y-m-d',strtotime("-1 week"));
$sql = "SELECT * FROM Meetings LEFT JOIN Minutes ON Meetings.meeting_id = Minutes.meeting_id INNER JOIN Rooms ON Meetings.meeting_id = Rooms.meeting_id WHERE  Rooms.date BETWEEN '" . $enddate . "' AND '" . date("Y-m-d") . "' AND Minutes.approval = 'approved' AND Meetings.meeting_id = " . $id;
mysql_query($sql);

答案 1 :(得分:0)

你的问题与:“Rooms.date”是一个varchar。 请尝试以下操作,但请注意,这将使Rooms.date字段上的索引无用。

将Rooms.date替换为:

STR_TO_DATE(Rooms.date, '%Y-%m-%d %T');

请查看:Mysql String to Date 您需要使用Rooms.date字段中使用的格式替换格式。 我使用的示例假设格式如下:'2010-10-15 12:34:22'

最好将Rooms.date改为实际日期时间数据类型