Church Code

January 9th | | Church | Tags: None

As long as i keep it “un-official”, then i THINK i can’t get into trouble
But then again, the church can request that i take down that thingy on the right side

While i’m at it, i may as well document everything i’m doing?

First thing, make the database

DROP TABLE IF EXISTS `joey`.`church`;
CREATE TABLE  `joey`.`church` (
  `Date` date NOT NULL,
  `Special` varchar(45) NOT NULL,
  `Worship` varchar(45) NOT NULL,
  `Song` varchar(45) NOT NULL,
  `Ushers` varchar(45) NOT NULL,
  `Pianist` varchar(45) NOT NULL,
  `Power` varchar(45) NOT NULL,
  `Cleaning` varchar(45) NOT NULL,
  `Speaker` varchar(45) NOT NULL,
  PRIMARY KEY (`Date`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

After that, you need to insert the data?

INSERT INTO  `joeylau_admin`.`church` VALUES ('yyyy-mm-dd','Special','Worship','Song','Ushers','Pianist','Power','Cleaning','Speaker');

And do that afew times?

Next, comes the PHP

<?php
$date=date('y-m-d');
$conn = mysql_connect('localhost', 'joeylau_*****', '************');
if (!$conn) {echo "Unable to connect to DB: " . mysql_error();exit;}
if (!mysql_select_db("joeylau_admin")) {echo "Unable to select joey: " . mysql_error();exit;}
$sql = "SELECT * FROM church WHERE `Date`>'$date' LIMIT 1;";
$result = mysql_query($sql);
if (!$result) {echo "Could not successfully run query ($sql) from DB: " . mysql_error();exit;}
if (mysql_num_rows($result) == 0) {echo "No rows found, nothing to print so am exiting";exit;}
while ($row = mysql_fetch_assoc($result)) {
$mysqldate = $row["Date"];
$phpdate = strtotime( $mysqldate );
$mysqldate = date('d M', $phpdate);

echo '<table border="1">';
	echo '<tr><th>Date:</th><td>' . $mysqldate . '</td></tr>';
	echo '<tr><th>Special Sunday:</th><td>' . $row["Special"] . '</td></tr>';
	echo '<tr><th>Worship Leader:</th><td>' . $row["Worship"] . '</td></tr>';
	echo '<tr><th>Song Leader:</th><td>' . $row["Song"] . '</td></tr>';
	echo '<tr><th>Usher:</th><td>' . $row["Ushers"] . '</td></tr>';
	echo '<tr><th>Pianist:</th><td>' . $row["Pianist"] . '</td></tr>';
	echo '<tr><th>Power Point:</th><td>' . $row["Power"] . '</td></tr>';
	echo '<tr><th>Cleaning (Annex):</th><td>' . $row["Cleaning"] . '</td></tr>';
	echo '<tr><th>Speaker:</th><td>' . $row["Speaker"] . '</td></tr>';
	echo '</table><br />';
}
mysql_free_result($result);
?>

Then, the last bit, add it to the site 😀

Leave a Reply

%d bloggers like this: