Good evening,
I am relatively new to PHP, but have been using the basic for a little while.
I am working on a new site and I am trying to make some of the pages a little more dyanmic.
I have a basic php page to display the birthdays or students.
Ideally, I would like this to be a single file, but for now, I have a seperate text file for each month, and my code opens the files for the current month and the next month within my code.
I used a while loop for each instance (i.e. one for the current month and one for next month).
However, my data only shows when I do a print inside the while loop. Even if I use a session, I get nothing. Can someone help, please? Here is the code for my birthday script below.
<?PHP
// this starts the session
session_start();
$current_birthdays=array();
$next_birthdays=array();
$current_birthdays['student']='Current_Birthdays';
$next_birthdays['student']='Next_Birthdays';
// this sets variables in the session
$_SESSION['current_birthdays']=$current_birthdays;
$_SESSION['next_birthdays']=$next_birthdays;
##print session_id();
## Main Section for Page information
$body_style = '<?php include ("templates/3col.php"); ?>';
$page_title = 'Frenchtown Elementary School - Birthdays';
## Page Content Section
$tagline = "";
$tagline_pic = '';
$page1_title = "";
$page1_link = '';
$page1_text = '';
$page2_title = "";
$page2_link = '';
$page2_text = '';
$news_date1 = "";
$news_topic1 = "";
$news_body1 = "";
$news_more = '';
$today = getdate();
$cMonth=$today[mon];
$nMonth=$today[mon]+1;
function getMonthName($Month){
$strTime=mktime(1,1,1,$Month,1,date("Y"));
return date("F",$strTime);
};
$current_month=getMonthName($cMonth);
$next_month=getMonthName($nMonth);
$cBirthday="data_files/" . "ft-bday-" . $current_month . ".txt";
$nBirthday="data_files/" . "ft-bday-" . $next_month . ".txt";
##if (!$file_handle = fopen($filename, 'r')) {
##echo "Cannot open file ($filename)";
##exit;
##}
## Get the current month birthday list
if (file_exists($cBirthday)) {
$file_handle = fopen($cBirthday,"r");
while (!feof($file_handle)){
$line_of_text = fgets($file_handle);
$current_birthdays=$line_of_text;
##$bday1 = explode('=', $line_of_text);
##$current_birthdays=$bday1."<br>";
##print $bday1."<br>";
};
fclose($file_handle);
} else {
echo "The file $cBirthday does not exist";
}
## Get the next month birthday list
if (file_exists($nBirthday)) {
$file_handle = fopen($nBirthday,"r");
while (!feof($file_handle)){
$line_of_text = fgets($file_handle);
$next_birthdays=$line_of_text;
##$bday2 = explode('=', $line_of_text);
##$next_birthdays=$bday2."<br>";
##print $bday2."<br>";
};
fclose($file_handle);
} else {
echo "The file $nBirthday does not exist";
}
## print $feed1[0]."<BR>". $feed1[1];
##$file_handle = fopen("data_files/ft-bday-bymonth.csv","r");
##var_dump($_SESSION['current_birthdays']);
##var_dump($_SESSION['next_birthdays']);
?>
<? include "templates/main.php"; ?>
I realize there is a bunch of code that can simply be stripped, but this is a work in progress right now.
I was originally going to have a single file in csv format, and use the explode function to populate an array based on the month of the students birthday. I didn't get very far with this, so I went with the individual month files which just list students by name.


