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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.