Jump to content

Display each calendar day's reading.


mezzmerized27

Recommended Posts

Greetings and Salivations!

 

Ok, I'm newish to php but I am constanly drawn deeper into it.

 

Be gentle and patient, please, I'm a quick study. ;)

 

My dilema:

 

There exists a Bible Reading Chart which divides the bible into daily segments.

For example:

 

January

1 Genesis 1-2 Matthew 1

2 Genesis 3-5 Matthew 2

etc.

 

Said chart was delivered to me as an .xls file.

 

I am tring to display a block of text containing "Genesis 1-2 Matthew 1" on January 1 and so on for each calendar day, so that each days reading selection will be automatically displayed on the proper date.

 

I have found many 'randomization' scripts to generate random quotes, but not much on displaying text (or another .html/.php page) by date.

 

My question is where to begin and what direction to face.

 

Can I pull the data directly from the spreadsheet? Should I rather convert it to a db? or a .txt?

 

Should I be using a php date function? Will I have an issue with handling dates between php and mysql?

 

I am running php5/mysql5 on Ubuntu 8.04 server.

 

Any help would be appreciated.

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/122330-display-each-calendar-days-reading/
Share on other sites

This is what I've got so far.

 

<html>
<head>
<title>Bible Reading Schedule</title>
</head>

<body>

<div align="center">

<?php

//if mysql
$con = mysql_connect("localhost","reading","reading");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

$date = date("F d Y");

echo "Today is $date.";
echo "Today's Bible reading section is " . "???????????????."

?>
</div>

</body>

</html>

 

Minus the data retrieval, this is close to what I need.

I am new to this as well but here are my thoughts.  I am not sure if it is possible to convert todays date IE 01 Jan 2008 to 001 a julian date.  If it is make a table with 365 items in it.  when someone logs into your page have a variable get the date convert it to julian and then pull that julian date number out of the table. 

 

Ex

ID             Scripture                          Script

001           Genesis 1-2 Matthew 1       In the beginning God created the heavens and the earth......

 

So now the date is equal to the id and have it pull that information.  I hope this makes sence to you.  There are probably easier ways to do this as I am still a rookie too.

 

<?php

//if mysql
$con = mysql_connect("localhost","reading","reading");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
$date = date("F d Y");
$juliandate = $date //this needs to be converted to julian date have no clue how to do it.  Possible make a constant with 01 Jan 08 then subtract 01 Jan 08 from current date. Not sure

$sql = 'SELECT * FROM `database` WHERE `id` = $juliandate';
$result = mysql_query($sql) or die(mysql_error());
$num_rows = mysql_num_rows($result);
$date = date("F d Y");

echo "Today is: " .$date;
echo "Today/'s Bible reading section is: " . $row['Scripture'];
echo  $row['Script'];

?>

 

Not sure if my syntaxt it correct but this should help.

Attila,

 

I've been super busy this week, but thanks so much for your reply.

 

I believe the php code works.

 

At least with a little modification.

 

<?php

$juliandate = date(z);

echo "$juliandate";

?>

 

Returns 249 for today (Saturday 06 September 2008).

 

So the date(z) returns the day of the year 1 - 365 (I guess this is the equivalent of mysql's DAYOFYEAR() function?).

 

My issues seem to lie on the db side.

 

I haven't quite figured out how to display the query results. I'm reading the mysql manual, but no luck yet.

 

Also, I had not yet created the database data when I started this code.

I have been using a table with only a handful of entries representing the surrounding several days.

 

As mentioned previously, I have an .xls.  ::)

 

So, I saved it as .csv.

 

Here is a small sample:

 

date,ot,nt

001,"Genesis 1-2","Matthew 1"

002,"Genesis 3-5","Matthew 2"

003,"Genesis 6-8","Matthew 3"

004,"Genesis 9-10","Matthew 4"

005,"Genesis 11","Matthew 5:1-26"

006,"Job 1-3","Matthew 5:27-48"

007,"Job 4-7","Matthew 6"

 

thru 365.

 

In trying to use phpmyadmin to import the data into a table, I got error messages.

 

MySQL said:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'date,ot,nt

001,"Genesis 1-2","Matthew 1"

002,"Genesis 3-5","Matthew 2"

003,"Gene' at line 1

 

But I'm getting off topic. I'm going to find the proper thread.  ;D

 

Thanks for your help.

Ok, this:

 

<html>
<head></head>
<body>
<div align="center">
<?php


$now = getdate(time());
$time = mktime(0,0,0, $now['mon'], 1, $now['year']);
$date = getdate($time);
$dayTotal = cal_days_in_month(0, $date['mon'], $date['year']);
//Print the calendar header with the month name.
print '<table><tr><td colspan="7"><strong>' . $date['month'] . '</strong></td></tr>';
for ($i = 0; $i < 6; $i++) {
	print '<tr>';
	for ($j = 1; $j <= 7; $j++) {
		$dayNum = $j + $i*7 - $date['wday'];
		//Print a cell with the day number in it.  If it is today, highlight it.
		print '<td';
		if ($dayNum > 0 && $dayNum <= $dayTotal) {
			print ($dayNum == $now['mday']) ? ' style="background: #ccc;">' : '>';
			print $dayNum;
		}
		else {
			//Print a blank cell if no date falls on that day, but the row is unfinished.
			print '>';
		}
		print '</td>';
	}
	print '</tr>';
	if ($dayNum >= $dayTotal && $i != 6)
		break;
}
print '</table>';


$host = "localhost";
$pass = "reading";
$user = "reading";
$database = "reading";



//if mysql
$con = mysql_connect("$host","$user","$pass");
mysql_select_db("reading");

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

  
  
$date = date("F d Y");
$juliandate = date(z); 

//query

$sql = 'SELECT * FROM `reading` WHERE `date` = "249"';
$result = mysql_query($sql) or die(mysql_error());
$num_rows = mysql_num_rows($result);
$row = mysql_fetch_array($result);

//output results
echo "Today's Bible reading section is " . $row['ot'] . " and ";
?>
<?php

echo  $row['nt'];



//Close the MySQL Link
mysql_close($con);



?>
</div>
</body>
</html>

 

though messy, returns the proper results (while today is dayofyear 249).

 

I still need a means of querying mysql for a column with a variable value equal to date(z)/DAYOFYEAR().  :'(

 

Any ideas?

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.