Page 1 of 1
need help with simple coding
Posted: Fri Jul 22, 2011 11:40 am
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!
Re: need help with simple coding
Posted: Fri Jul 22, 2011 12:28 pm
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

Re: need help with simple coding
Posted: Fri Jul 22, 2011 12:40 pm
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.
Re: need help with simple coding
Posted: Fri Jul 22, 2011 12:51 pm
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?
Re: need help with simple coding
Posted: Fri Jul 22, 2011 1:12 pm
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.
Re: need help with simple coding
Posted: Sat Jul 23, 2011 1:13 am
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.