Forum Moderators: coopster

Message Too Old, No Replies

php and mysql data pull

         

loki

9:03 pm on Jan 14, 2012 (gmt 0)

10+ Year Member



i have made this script and its just not pulling the photo table to show it but only for 7 days from being added

<?php
mysql_connect("127.0.0.1", "#*$!xx", "#*$!#*$!") or die(mysql_error()) ;
mysql_select_db("member") or die(mysql_error()) ;

$sql = mysql_query("SELECT * FROM member WHERE DATE BETWEEN '".date('Y-m-d',strtotime('now'))."' AND '".date('Y-m-d',strtotime('-7 days'))."' ORDER BY ID DESC");
$result=mysql_query($sql);
?>
<?php
while($rows=mysql_fetch_array($result))
?>
[#*$!#*$!xx...] echo $rows['photo']; ?>

rocknbil

8:59 pm on Jan 16, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try using the date and time functions from mysql.

$sql = mysql_query("SELECT * FROM member WHERE `DATE` BETWEEN now() AND date_sub(now(), interval 7 day) ORDER BY ID DESC");

or

$sql = mysql_query("SELECT * FROM member WHERE `DATE` <= now() AND `DATE` >= date_sub(now(), interval 7 day) ORDER BY ID DESC");

Also beware that now() is a date/time value

2012-16-01 12:23:45

and curdate() is a date only value - you may want curdate() instead. It depends what value your date field holds.

2012-16-01

Note the backticks . . . . date is a reserved word in mysql (see link below, date() function which does something completely different than you'd expect,) and it's not wise to use as a field name. But if you do, you must backtick it (not quote!) so mySQL will know what you're asking.

mySQL Date and Time Functions [dev.mysql.com]