im working on a site and i would like to display the newest members within 30 days. how would i do this.

im using mysql database. when the person signs up, it records the current date into their row.

my module should show people that have signed up within the last 30 days.

would anybody know how to do this???

much regards

ok i suggest taking the date from the db. Then using a algorithm to figure out if the date selected subtracted from todays date is larger then 30.
The algorithm could be like this.
We need to add a new field in the db. Lets call this b30. This stands for bigger then 30. This will be used to help make understanding whether its 30 days old easier. When a user signs up, this field will have a default value of lets say smaller. This will automatically fill in when a user signs up so dont worry about adding a new value to your insert query.
So for the module:
First it will find out todays date, then use a string explode function to separate the days and month. So we are left with 2 values todays day value and today's month value. Lets call them tday and tmonth. Next we need to do the same thing with the results from a mysql query where b30 = smaller. Next we need to do a string explode function so we are left with 2 values the sign up date's month and day. Lets call these oday and omonth. Now we need to figure out if its smaller then 30 days old. I assume the month is in number format. So lets just, to make everything easier, simplify it by saying there are 30 days in every month, i know this is not the case! What we need to do is to subtract tmonth from omonth. If the answer = 1 then we can continue with this date. Basically what the 1 means is that the maximum difference of days are 30. Now all we need to do is to subtract the tday from the oday. So say the tday is 15 and they oday is 6 we will get an answer of 9. Now if we remember we chose a maximum of 1 month's difference. This means that the user must of signed up 21 days ago. Within the 30 days limit. Then all we need to do is echo up the information. Yet if the tmonth and omonth equation does not equal to 1 when then we update the b30 field and change it to bigger so it wont be included in the algorithm again. DONE!

if you dont understand and want it in more detail I will re-type it! Its just im in a bit of a rush,

but i hoped i helped!

Well i understand how to do it - algorithm wise, but im newer to PHP or just (code) in general.
but im confused on the built in function part. like date(), and adding dates and subtracting dates and transforming them to strings.
i can write the querys, i know what i need to do with the math part. i just dont get what i need to use with the special php part.

hope i explained myself better.

regards.
oh and thanks for the explanations

ok - just to say i also figured there is a flaw in my algorithm, but it can be fixed so ignore the top bit! Perhaps you could tell me your algorithm that you will use and i can help write the code.

You could try something like this:

$q = @mysql_query("SELECT * FROM users WHERE datediff(NOW(), registration_date) < 30");

i found what i was working on a few weeks ago.
i was trying somethings. if you were to run this in a browser it will be "easy to understand" atleast i hope.

idk hopefully you see what i was trying to do.

<?php


$today = date('j F Y');

echo "<br />";
echo "today: " . $today;

$register_date = date('j F Y',strtotime('-15 days'));

$addition = date('j F Y',strtotime('+30 days'));
echo "<br />";
echo "addition: " . $addition;
echo "<br />";
echo "register date: " . $register_date;
$deadline = $register_date + $addition;

echo "<br />";
echo "deadline: " . $deadline;
$difference = $today - $register_date;

echo "<br />";

echo "difference: " . $difference;


echo "<br />";

if ($difference > $deadline ){

echo "cant see the members";

}else{

echo "im a member";

}

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.