mwarby Posted March 12, 2006 Share Posted March 12, 2006 I'm trying to generate a list of dates each one being 7 days on from the last,I then hope to query a database to check if this date has been reserved.at the moment I'm trying just to get the basic list weh I use$query='select adddate('2006-02-01',interval 7 day)';$result=mysql_query($query);echo mysql_result($result,0);I get the expected result I tried putting it in a for loop as belowfor($counter=1;$counter<28;$counter+=7){$query='select adddate('2006-02-01',interval $counter day)';$result=mysql_query($query);echo mysql_result($result,0);}but i get Parse error: parse error, unexpected T_LNUMBER in /home/knott/domains/knottcottage.co.uk/public_html/avail.php on line 17my complete code is below<html><head><title>Availabilty Checker</title></head><body><h1> Availabilty checker </h1><?php$dbhost = 'localhost';$dbuser = 'knott_book';$dbpass = '1234';$database = 'knott_booking';echo 'test1';mysql_connect(localhost,$dbuser,$dbpass);@mysql_select_db($database) or die( "Unable to select database");for($counter=1;$counter<28;$counter+=7){$query='select adddate('2006-02-01',interval $counter day)';$result=mysql_query($query);echo mysql_result($result,0);}?></body></html>Thanks for readingMartin Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted March 12, 2006 Share Posted March 12, 2006 Change your query to:[code]$query="select adddate('2006-02-01',interval $counter day)";[/code]With the single quotes on the outside, then using them again for the date, you were escaping the string, which would cause you to get an errror. If it had made it as far as your variable, it would not have replaced the $counter variable with it's value, as the single quotes cause it to take all text literally. Quote Link to comment Share on other sites More sharing options...
mwarby Posted March 19, 2006 Author Share Posted March 19, 2006 [!--quoteo(post=354216:date=Mar 12 2006, 11:27 AM:name=hitman6003)--][div class=\'quotetop\']QUOTE(hitman6003 @ Mar 12 2006, 11:27 AM) [snapback]354216[/snapback][/div][div class=\'quotemain\'][!--quotec--]Change your query to:[code]$query="select adddate('2006-02-01',interval $counter day)";[/code]With the single quotes on the outside, then using them again for the date, you were escaping the string, which would cause you to get an errror. If it had made it as far as your variable, it would not have replaced the $counter variable with it's value, as the single quotes cause it to take all text literally.[/quote]Thanks a lot thats that problem sorted :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.