Fixing a Small Scripting Problem
Website Automation with PHP and MySQL, Part 6
Low End Mac Reader Specials
Memory To Go Special: New 2008 iMac 2GB $42 / iMac Intel Core2 DUO & MacBook Pro 2GB $36 - 1GB $20. MacPro 8 Core Memory 8GB kit $286 / 4GB kit $143 / 2GB kit $93 -- Free shipping available. LIfetime warranty.
Download Typestyler, still the Ultimate Styling Tool for Internet, Print and Video Graphics. Works great in Classic with a Native OS X Version on the way. Free Tryout: www.typestyler.com
LA Computer Company: Specials on AppleCare, iMac's, Apple Batteries and Apple A/C Adapters. Also Great prices on Used Apple Computers. Call 1-800-941-7654 Click Here.
OWC: OWC Mercury On-The-Go FW400/800/USB2/eSATA Portables High Performance A/V Rated, **Bus Powered** **Up to 500GB in the Palm of your Hand** Macworld Editor's Choice, CNET 'Very Good' - from $75.99!
Mac users can finally play Party Poker for Mac. Not only that, they can also learn how to play PokerStars for Mac.
Laptop Hardware Provided by TechRestore - Overnight Mac & iPod Repairs.
Compare products like desktop computers, laptops, and LCD TVs side by side! All the information and reviews to make the best purchasing decision for a new cell phone GPS products or MP3 players. The Ciao network makes searching products easy for you.
Dan Knight - 2002.05.10
This morning I discovered a problem with the PHP scripts we use to display the Mac of the Day and Email List of the Day.
My #2 son Brian <http://brkn.net/> and I came up with the following code to display the Mac of the Day:
- <?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> <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> <A HREF=\"$query[link]\">$query[listname]</A><BR>";
- ?>
Notice the line near the middle - $mod = $today % 89;
That line tells PHP to use modulo arithmetic to divide today's date (converted to a number) by 89 and discard everything but the remainder. This would give us 89 unique values - just what we need with 89 entries in the Mac of the Day database.
The problem is, modulo arithmetic returns a remainder from 0 (zero) to one less than your maximum number, so our function was using numbers from 0 to 88. And our database uses numbers from 1 to 89.
We use a similar function to handle the 38 email lists, and that's where I noticed the problem this morning. Today the email list script was returning zero, so no list was displayed.
All we have to do is add one to the number returned to have values in the range we need. I've modified two lines, uploaded the new script, and now everything works:
$mod = ($today % 89) + 1; $lod = ($today % 38) + 1;
The Next Project
I'd planned on automating site links next, but have instead decided that the next project will be automating the Deal of the Day. This will involve real calendar dates, not raw numbers based on seconds since 1970.01.01.
I hope to cover this project next week.
Recent Online Tech Journal Columns
- Apple's AAUI ethernet connector, 09.04. From 1991 through 1995, Apple used a proprietary ethernet connection. Why they created AAUI and where to find adapters.
- PowerPC G5: Apple's last fling with PowerPC architecture, 05.24. Teaming up with IBM, Apple adopted the PowerPC G5 in 2003 - and phased out the last G5 Power Mac three years later.
- The PowerPC G4: From 350 MHz to 2.0 GHz, 05.24. AltiVec and dual processor support made the G4 a big improvement over the earlier G3 processor.
- The PowerPC G3 story: From 233 MHz to 1.1 GHz, 05.24. The history of the PowerPC 750 family and its use in Apple computers from 1997 through 2004.
- More in the Online Tech Journal index.
Links for the Day
- Mac of the Day: SuperMac S900, Aug. 1996 - This 6-slot tower supported dual CPUs and still has a following.
- List of the Day: Macintel List for discussion and support of Intel-based Macs.
- October 7 in LEM history: 98: Love that PowerBook G3 - 99: Troubleshooting 101 - Love at first sight - 02: Hot rodding a Power Mac for OS X - Beefing up Windows networking - 05: Choose FireWire 800 over USB 2.0 and FireWire 400 - Faster Mac minis shipping - Speedy 100 GB 7200 rpm notebook drives
Recent Content on Low End Mac
- New Apple Notebooks at Zero Minus One Week, Charles W. Moore, 'Book Value, 10.07. It's widely anticipated that Apple will overhaul the MacBook Pro and MacBook lines next Tuesday. What should we expect?
- How to Clone Mac OS X to a New Hard Drive, Simon Royal, Mac Spectrum, 10.07. Whether you want to put a bigger, faster drive in your Mac or clone OS X for use in another Mac, here's the simple process.
- Best 12" PowerBook G4 Deals, Low End Mac Deals, 10.07. Used 867 MHz Combo, no APX, $490; 1.33 GHz, $496; 1.5 GHz SuperDrive, $542.
- Best Mac mini Deals, Low End Mac Deals, 10.07. Used 1.25 GHz G4 Combo, $399; 1.42 SuperDrive, $559; 1.66 Core Duo, $499; new 1.83 Core 2 Combo, $570 after rebate; 2.0 SD, $770 a/r.
- Best Power Mac G3 and PCI Video Card Deals, Low End Mac Deals, 10.07. Used beige 300 MHz, $25; 333, $198; blue & white 300, $49; 350, $55; 400, $90; 450, $105; PCI video cards from $15.
- $19,800 Bentley Ego Laptop Remarkably Similar to 1999 Clamshell iBook, Charles W. Moore, Miscellaneous Ramblings, 10.06. Granted, Apple's iBook didn't have white gold trim, a padded leather exterior, or come in colors to match your Bentley automobile.
- The Cost of Moving to Small Business Server vs. Moving to Leopard Server., Andrew J Fishkin, Best Tools for the Job, 10.06. Upgrading the existing SBS 2003 Server would cost less, the the server will run up against hardware limitations long before a Mac Pro does.
- Use Your FileMaker Pro Databases on Your iPhone, Adam Rosen, Adam's Apple, 10.06. Although there's no version of FileMaker Pro for the iPhone, FMTouch will let you use your data and layouts on it.
- Best eMac Deals, Low End Mac Deals, 10.06. Used 700 MHz CD, $110; CD-RW, $130; Combo, $170; 800 CD, $170; 1 GHz Combo, $250; SuperDrive, $280; 1.25 Combo, $290; SD, $360; 1.42 Combo, $359.
- Best MacBook Air Deals, Low End Mac Deals, 10.06. Used 1.6 HD, $1,299; refurb, $1,499; new, $1,669 after rebate; 1.8, $1,919 a/r; 1.6 SSD, $2,294 a/r; used 1.8 SSD, $1,997; refurb, $2,299; new, $2,349 a/r.
- Best iPod shuffle Deals, Low End Mac Deals, 10.06. Refurb 3G/1 GB, $39; 2 GB, $59; new 1 GB (3G or 4G), $47; 2 GB (3G or 4G), $67. Prices include ground shipping.
- Mac Netbook Coming?, $179 64 GB SSD, Apple Owns 20% of US Notebook Market, and More, The 'Book Review, 10.03. Also head of Norton AntiVirus team uses a Mac, Toshiba demos new battery technology, 1 TB notebook drives due in 2010, bargain 'Books from $150 to $2,699, and more.
- Getting the Most from Your G3 Mac, Simon Royal, Mac Spectrum, 10.03. Most G3 Macs can be upgraded so they can run Mac OS X 10.4 'Tiger' quite nicely. Here's how.
- Apple Drops iPhone NDA, Defecting to Android, Auto Performance Apps for the iPhone, and More, iNews Review, 10.03. Also more research needed on cellphone cancer link, file sharing app for the iPhone, three new power accessories from Macally, several new iPhone apps, and more.
- Best Power Mac G4 and AGP Video Card Deals, Low End Mac Deals, 10.03. Used 450 MHz, $75; 500, $99; 733, $150; 800, $199; 1.25 GHz, C$349; 867 MHz dual, $225; 1 GHz, $349; 1.25, $499; 1.42, $600.
- OS X and Safari Shares Grow in September, Toxic Mac Pro?, Green Hard Drives, and More, Mac News Review, 10.03. Also Vista terrible as Mac market grows, CrossOver Mac Pro reviewed, SimpleTech Pro Drives, and a new toolkit for working on computers.
- Best iBook G3 Deals, Low End Mac Deals, 10.03. Used 300 MHz clamshell, $150; 366, $199; 500 CD, $149; 800, $190; 600 CD-RW, $240; 800 Combo, $300; 900, $399; 14" 600, $360; 900, $469.
- Best Mac OS X 10.0-10.3 Deals, Low End Mac Deals, 10.03. Mac OS X 10.0.3, $30; 10.1, $20; 10.2, $60; 10.3 CD, DVD, $100; CD, $119; 10.1 Server, unlimited users, $65; 10.3 Server, unlimited, $150.
- More links in our archive.
Go to the Online Tech Journal index.
About LEM | Support | Usage | Privacy | Contacts

