Jump to content

[SOLVED] Select items from certain date


timmah1

Recommended Posts

I have a field in my database called purchase. I is formatted like 2009-01-30

 

I need to select items from the form with only the month and the year, depending on the users entry.

It is for a purchase history.

 

I have this code, but it's not working.

<?php
$year = mysql_real_escape_string($_POST['year']);
$month = mysql_real_escape_string($_POST['month']);

$query3 = "SELECT * FROM affiliates1 WHERE purchase = '".date("m", strtotime($month))."' AND '".date("Y", strtotime($year))."'";
$w3 = mysql_query($query3) or die(mysql_error());
while ($b3 = mysql_fetch_array($w3)) {

	echo $b3['id']."<br />";
}
?>

 

Can somebody show me the correct way?

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/166008-solved-select-items-from-certain-date/
Share on other sites

No. I have a table in the database formatted as date (Y-m-d)

 

I have a form where a user can select a month and year to view their purchase history.

 

I got it to work with this

<?php
$year = mysql_real_escape_string($_POST['year']);
$month = mysql_real_escape_string($_POST['month']);
$aff_id = mysql_real_escape_string($_POST['user']);

$query3 = "SELECT * FROM affiliates1 WHERE DATE_FORMAT(`purchase`,'%Y-%m') = '$year-$month' AND affil_id = '$aff_id'";
$w3 = mysql_query($query3) or die(mysql_error());
           while ($b3 = mysql_fetch_array($w3)) {

	echo $b3['id']."<br />";
  }
?>

 

Thanks for the response though

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.