Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7011351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:06:57+00:00 2026-05-27T22:06:57+00:00

I’m wanting to extract data from a mySQL database which shows the members with

  • 0

I’m wanting to extract data from a mySQL database which shows the members with a subscription date which has expired 2 months or more from the current date. i.e. the day I run my PHP report.

I’ve tried using the query below to pull the data from my database, but it’s not extracting any data.

$result = mysql_query("SELECT userid, forename, surname, subscriptionexpiration FROM {$table} WHERE subscriptionexpiration BETWEEN DATE_SUB(now(), INTERVAL 2 MONTH) AND now() ORDER BY userid DESC"); 

The date is stored in my database as ddmmyy, so I’m not sure whether this is the issue or whether my query is incorrect.

Full Script

<?php
$db_host = 'hostname';
$db_user = 'username';
$db_pwd = 'password';

$database = 'databasename';
$table = 'userdetails';
// use the same name as SQL table

if (!mysql_connect($db_host, $db_user, $db_pwd)) 
die("Can't connect to database"); 

if (!mysql_select_db($database)) 
die("Can't select database"); 


function sql_safe($s)  
{      if (get_magic_quotes_gpc())  
        $s = stripslashes($s);  

    return mysql_real_escape_string($s);  
}  

if ($_SERVER['REQUEST_METHOD'] == 'POST')  
{  
    if (isset($_POST["submit"]))  
    {  
        if (isset($_POST['del'])) 
            $userid = intval($_POST['del']); 

        if (mysql_query("DELETE FROM {$table} WHERE userid={$userid}")) 
            $msg = 'The member who you selected has now been deleted!';  
        else 
            $msg = 'Could not delete the selected member'; 
    } 
}  
?> 
<html><head> 
<title>Members With 2 Month Subscription Expiration</title>
<style type="text/css">
<!--
.style1 {
    color: #FFFFFF;
    font-size: 18px;
    font-family: Calibri;
}
.style2 {
    font-size: 18px;
    font-weight: bold;
    font-family: Calibri;
}
.style3 {font-family: Calibri}
.style6 {font-size: 16px}
.style7 {font-family: Calibri; font-size: 16px; }
-->
</style>
</head> 
<body>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p class="style7">
<?php 
if (isset($msg)) // this is special section for 
// outputing message 
{ 
?></p>
<p class="style7">
  <?=$msg?>
</p>
<?php 
} 
?>
<form action="<?=$PHP_SELF?>" method="POST" enctype="multipart/form-data"> 
<?php 
$result = mysql_query("SELECT userid, forename, surname, subscriptionexpiration FROM {$table} WHERE subscriptionexpiration > now() and datediff(month, now(), subscriptionexpiration) >= 2 ORDER BY userid DESC");    if (mysql_num_rows($result) == 0) // table is empty 
echo 'There are currently no members where their "Subscription Date" is greater than two months!'; 
else 
{ 
echo "<table>\n"; 
while(list($userid, $forename, $surname, $subscriptionexpiration) = mysql_fetch_row($result)) 
{ 
echo "<tr>\n" 
."<td><input type='radio' name='del' forename, surname value='{$userid}' /></td>\n" 
."<td><small>{$forename} {$surname}</small><td>\n" 
."<td><small>{$subscriptionexpiration}</small><td>\n" 
."</tr>\n"; 
} 
echo "<tr><td colspan=\"3\">"; 
echo '<input type="submit" value="Delete Selected Member" name="submit"/>'; 
echo "</td></tr>"; 
echo '</table>'; 
} 
?> 
<input type="hidden" name="action" id="action" /> 
</form> 
</body>
</html>

Solution

("SELECT userid, forename, surname, subscriptionexpiration FROM {$table} WHERE subscriptionexpiration <NOW() - INTERVAL 2 MONTH ORDER BY userid DESC");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:06:57+00:00Added an answer on May 27, 2026 at 10:06 pm

    In your ‘where’ clause use datediff. This would look like

    $result = mysql_query(
          "SELECT userid, forename, surname, subscriptionexpiration 
             FROM {$table}  
             WHERE subscriptionexpiration > now() and  
                 datediff(month, now(), subscriptionexpiration) <= -2 ORDER BY userid DESC");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.