in the mysql table more then ten date column records there. i want select only last insert date record ,next i want selected date add 7 days in the date to store db again person want insert again select the last record then add 7 days selected last date ........ help me...

below the my code

<?php

$ques=$_REQUEST['ques'];

$host="localhost";
$user="";
$pass="";
$dbid="cdsemplo_poll";
$link=mysql_connect($host,$user,$pass);
mysql_select_db($dbid) or die("not connect");

$date=mysql_query("select date from poll1");

if(isset($_REQUEST['insert']))
{

// below the 2 line only add current date so i want insert the last date get the date from db to add 7 days next if person want to insert the another data same thing come to again


$tomorrow = mktime(0,0,0,date("m"),date("d")+7,date("Y"));
$d=date("Y/m/d", $tomorrow);
 
mysql_query("insert into poll1(question,date) values('$ques?','$newDate')");
}
mysql_close($link);

?>

For the last date use:

order by datefield desc

For 7 day and more days:

Between Date() And DateAdd("d",-7,Date())

DATE_ADD() ,Add two dates
DATE_SUB() ,Subtract two dates

use the above both functions....

thank you for reply ...
i selected last record in date field ....
next i want add 7 days selected date .i used that function not working ..

$ques=$_REQUEST['ques'];

$host="localhost";
$user="";
$pass="";
$dbid="cdsemplo_poll";
$link=mysql_connect($host,$user,$pass);
mysql_select_db($dbid) or die("not connect");


$result=mysql_query("SELECT * FROM poll1 order by desc");



while($row=mysql_fetch_array($result))
{
$dat1=$row['date'];

}

echo "$dat1";

i want add 7 days selected $dat1 then i want store to db..

thisbelow the code adding only current date but i want add 7 days when ever selected this page ...

$nextWeek = dat1 + (7 * 24 * 60 * 60);
                   // 7 days; 24 hours; 60 mins; 60secs
echo 'Now:       '. date('Y-m-d') ."\n";
//echo 'Next Week: '. date('Y-m-d', $nextWeek) ."\n";
// or using strtotime():
echo 'Next Week: '. date('Y-m-d', strtotime('+1 week')) ."\n"; // this line print after 7 days only not add database date 
   

if(isset($_REQUEST['insert']))
{


mysql_query("insert into poll1(question) values('$ques?')");
}
mysql_close($link);
This article has been dead for over six months. Start a new discussion instead.