need help with simple coding

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
realsole
Forum Newbie
Posts: 3
Joined: Fri Jul 22, 2011 11:33 am

need help with simple coding

Post by realsole »

Hello, newbie, here. Need help with adding the following to my site. Thanks a bunch in advance.
I already have two php databases and a site that draws info from these databases:
Member: Member ID with registration date
Message: Message ID with corresponding message

What I would like to do is show a particular message based on how many days have elapsed since registration date.
For example, 1 day after registration, display the message for Message ID=1.
100 days after registration, display the message for Message ID=100.

What code do I need to display this? Thanks a bunch!
Last edited by realsole on Fri Jul 22, 2011 12:41 pm, edited 1 time in total.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: need help with simple coding

Post by social_experiment »

realsole wrote:What I would like to do is show a particular text based on how many days have elapsed since registration date.
For example, 1 day after registration, display the text for Text ID=1.
100 days after registration, display the text for Text ID=100.
You would have to extract the information from the database using a query that matches what you want to find

Code: Select all

<?php
 $query = "SELECT something FROM table WHERE text = '" . mysql_real_escape_string($particularText) . "' ";
 $sql = mysql_query($query);
?>
From there you would use a function like mysql_fetch_array() to display the information. If you can create a bit of the script it will be easier (and more benificial for you) to help :)
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
realsole
Forum Newbie
Posts: 3
Joined: Fri Jul 22, 2011 11:33 am

Re: need help with simple coding

Post by realsole »

This is the script I'm working with:

<?php
$sql=mysql_query("select msg_id,message from tbl_messages where msg_id='5'");
while($row=mysql_fetch_array($sql))
{
$id=$row['msg_id'];
$message=$row['message'];
?>
<div class="block" id="<?php echo $message;?>">
<center>Today's Message</center>
</div>
<?php
}
?>

This would be the script for day 5.

What I don't know how to do is replace the 5 with the difference between current date and the registration date.
$reg_date = $row['member_reg_date'];
from tbl_members


I would appreciate your help. Thanks.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: need help with simple coding

Post by social_experiment »

realsole wrote:What I don't know how to do is replace the 5 with the difference between current date and the registration date.
What determines which registration date is selected; a specific user id or do you select all registration dates?
What is the format of the date retrieved?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
realsole
Forum Newbie
Posts: 3
Joined: Fri Jul 22, 2011 11:33 am

Re: need help with simple coding

Post by realsole »

The registration date is established by member ID, on the date the member registers. This data resides in the member table, tbl_members.

The registration date is unique to each member.

I wish to have each member see a progression of messages that change as the number of days from registration changes. This means each member, after he/she logs in, sees their unique message based on how many days it has been since registration.

Thanks in advance.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: need help with simple coding

Post by social_experiment »

realsole wrote:The registration date is established by member ID, on the date the member registers. This data resides in the member table, tbl_members.
The query to select the regsitration date could look like this

Code: Select all

<?php
 $query = "SELECT registration_date FROM tbl_members WHERE id = '" . $memberID . "' ";
?>
id is the field in which you store your member id values. You didn't mention what format this date is stored in because it would likely have to be converted before the amount of days passed can be calculated.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply