Low End Mac's Online Tech Journal

Testing and Making Your PHP Work

Website Automation with PHP and MySQL, Part 5

Dan Knight - 2002.04.29

Last time we coded our PHP to work with our MySQL database and call up a different Mac of the Day each day.

Testing

After all that, it should have worked the first time - and it did.

Of course, that wasn't good enough. We'd created a full HTML page that worked, but we needed to be able to call this up from various pages on the site. test.html became test.txt, a file that would be called via Server Side Include - and then it didn't work any more.

Brian <http://brkn.net/> and I put our heads together, renamed the file test.php, called it that way, and it worked. On our server, you apparently have to make it part of the main HTML file or call it up in a file with the .php extension.

Then we tried to call the .php file from within a .txt file. We discovered that our server doesn't want to run .php files nested within include files. We'd have to modify the code on all the pages linking to the Mac of the Day to call in first a .txt file, then our new .php file, and then a closing .txt file.

That worked.

Adapting

The next step was to create a database for the email list of the day. The biggest difference here is that our list contains both Low End Mac email lists and a whole bunch run by The Macintosh Guy of Portland, so we'd need to use a full URL in the database. After creating the Mac of the Day, this was pretty trivial.

We also link to the Mac of the Day and the List of the Day in the navigation bar on the right side of almost every page on the site. Here we don't include the long text description, so we modified our code to look like this:

<?php
$host = "sqlserver.lowendmac.com";
$username = "MyName";
$password = "MyPassword";
$connection = @mysql_connect($host,$username,$password);
mysql_select_db(lem_mod,$connection);
$today = round((date(U) + 32400) / 86400);
$mod = $today % 89;
$query = mysql_fetch_array(mysql_query("select * from mod where id = '$mod'"));
echo "<B><BR>Mac of the Day</B><BR>&nbsp;<A HREF=/$query[link]>$query[model]</A>";
$lod = $today % 38;
$query = mysql_fetch_array(mysql_query("select * from lists where id = '$lod'"));
echo "<B><BR>List of the Day</B><BR>&nbsp;<A HREF=\"$query[link]\">$query[listname]</A><BR>";
?>

Pretty trivial, but we ran into the same problem we'd had with the Mac of the Day bullet list - it had to be called in as a .php file. This became very time consuming, as we have thousands of pages on the site that used the menu.txt navigation file. In every single instance, we would have to replace that Server Side Include call with calls to a .txt file, a .php file, and another .txt file.

Using BBEdit Lite, that was also pretty trivial - but uploading thousands of changed pages probably took 3-4 hours. I hope we never have to go through that again.

It Just Works

So now pretty much every page on the site makes a couple of PHP calls to our MySQL database - once to display the Mac of the Day and then to display the Email List of the Day. Day in, day out the server automatically changes this sometime after midnight in Silicon Valley - even on weekends, even on holidays, even if I go on vacation.

And isn't that the whole point of computers, automating tedious tasks?

Next up: Houston, we have a problem.

Join us on Facebook, follow us on Twitter or Google+, or subscribe to our RSS news feed

Today's Links

Recent Content

About LEM Support Usage Privacy Contact

Custom Search

Follow Low End Mac on Twitter
Join Low End Mac on Facebook

Favorite Sites

MacSurfer
Cult of Mac
Shrine of Apple
MacInTouch
MyAppleMenu
InfoMac
The Mac Observer
Accelerate Your Mac
RetroMacCast
The Vintage Mac Museum
Deal Brothers
DealMac
Mac2Sell
Mac Driver Museum
JAG's House
System 6 Heaven
System 7 Today
the pickle's Low-End Mac FAQ

Affiliates

Amazon.com
The iTunes Store
PC Connection Express
Macgo Blu-ray Player
Parallels Desktop for Mac
eBay

Low End Mac's Amazon.com store

Advertise

Open Link