timmah1 Posted July 15, 2009 Share Posted July 15, 2009 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 Quote Link to comment Share on other sites More sharing options...
PugJr Posted July 15, 2009 Share Posted July 15, 2009 I don't really understand. Are you wanting to explode 2009-01-30 into a month and year variable? Quote Link to comment Share on other sites More sharing options...
timmah1 Posted July 15, 2009 Author Share Posted July 15, 2009 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 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.