Low End Mac Reader Specials
TypeStyler For Mac OS X is Now Shipping! Download The Free Fully Functional 60 Day Tryout at www.typestyler.com
OWC: Mercury On-The-Go FW800+USB2 up to 1.0TB. Bus Powered, no external power supply needed. Macworld Editors Choice, CNET Very Good Starting from $99.97, 500GB $159.99. Click here
Don't install Parallels to play poker online! Poker Mac will show you how
to download and install a native Mac poker application such as Full
Tilt Poker Mac.
Laptop Hardware Provided by TechRestore - Overnight Mac & iPod Repairs.
Compare products like desktop computers, apple laptops, apple macs, and LCD Monitors side by side! All the information and reviews to make the best purchasing decision for new mobile phones, sat nav systems, or MP3 players. The Ciao online shopping community makes searching products easy for you.
Low End Mac's Online Tech Journal
Managing Local Links with PHP and MySQL
Website Automation with PHP and MySQL, Part 12
Dan Knight - 2002.07.03
We've finally finished automating link updates on the home page, the WebTV home page, the mobile edition home page (a subscriber-only feature), and most editorial content. It's been quite a project.
Creating the "local links" database was pretty simple, although we did have a few different fields compared to the external links database. Because most of our new content is available in regular, WebTV, and mobile versions (the latter especially formatted to work well on Palms), we need to track three different URLs. Here's the naming convention we use:
- General: http://lowendmac.com/column/02/0703.html
- Mobile: http://lowendmac.com/column/02/0703.htm
- WebTV: http://lowendmac.com/column/02/0703w.htm
Every link on the site begins with "http://lowendmac.com", so we don't have to include that part in our database. And rather than create three longer records with the balance of the URL, we use four: one to hold the "/column/02/" part and three to hold the general, mobile, and WebTV final part of the URL.
Entries are dated by their publication date and also time stamped with a Unix time code when entered into the database, just like we did with external links. In fact, except for having to track three types of pages, the local links database is very similar to the external links database.
Displaying the Data
Where things become very different is when we display the data. For external links, sorting by time stamp is fine, but we run into some issues - and some opportunities.
First, I want to include a link to "Today in LEM History." This could come first, but I prefer to focus on the new content and want the history link to show up after today's new articles. That means somehow separating today's links from yesterday's.
And that brings up another issue - days with no updates. I don't usually add content over the weekend or on holidays. So we can't simply search for today's date; we have to search for the most recent date and display that first.
Brian, who has been helping me a lot with this, was on a church sponsored mission trip in Washington, D.C., last week, so Stephen, our 14-year-old PHP wizard and the publisher of PetCube.com (which gets more traffic every day than Low End Mac!), helped me out.
Here's the snippet of code that finds that most recent date:
$latestdate = mysql_fetch_array(mysql_query("SELECT * FROM links ORDER BY timestamp DESC LIMIT 1"));
And here's the code that displays local links for that day:
- $get_links = mysql_query("SELECT * FROM links WHERE pubdate = '$latestdate[pubdate]' ORDER BY timestamp DESC");
- while ($array = mysql_fetch_array($get_links))
- {
- echo "<li>";
- if ($array[flag]<>"")
- {echo"<img src=/art/$array[flag].gif width=17 height=13 align=middle> ";}
- echo "<a href=\"$array[path]$array[html]\">$array[linktext]</a>, ";
- if ($array[author]<>"")
- {echo"$array[author], ";}
- if ($array[columnname]<>"")
- {echo"$array[columnname], ";}
- echo "$array[pubdate].
- $array[description]</li>";
- }
This creates a bullet list item for local content just like we did last week with external links.
Next we add our history link with the following code:
- $thisdate = date(md);
- $thisrecord = date(nd);
- $today = date("F j");
- $get_links = mysql_fetch_array(mysql_query("SELECT * FROM lemhistory WHERE datefield = '$thisrecord'"));
if ($get_links == "") {die ("no record");}echo "<li> <a href=\"/arc/$thisdate.html\">$today in LEM history:</a>$get_links[stories]</li>";
|
We discovered the above code didn't quite work on July 8, when we had no archive link. Here's how the revised code:
The difference is that instead of telling this subroutine to die if there is no record, we now tell it to display a record if there is one. Problem solved. |
Our archive filenames are of the format MMDD, but our MySQL database strips off the leading zero in our integer field, which is why we need both $thisdate and $thisrecord. $today displays the date using the full name of the month and the one or two digit day. If there is no record for a specific date, which happens maybe twice a month, no LEM archive link is displayed.
After this, we need to display the previous day's links, and here's where we have a unique opportunity to change the sort order from timestamp to something else.
As you may recall, we had to call a second PHP script to create a counter for external links. With local links, I'm less concerned with how many times a link is followed from our home page and more interested in how many times the article itself is read. So instead of calling a second PHP script that increments the counter and then leads to the article in question, I've put a small PHP script on the article's page that increments the counter every time the article is read - even if it's being linked from MacSurfer or another outside source.
Based on the assumption that the article that most people read one day is the one from that date that will generate the most interest the next day, instead of sorting older links by timestamp, we sort them by popularity.
- $previous_date = mysql_fetch_array(mysql_query("SELECT * FROM links WHERE pubdate != '$latestdate[pubdate]' ORDER BY timestamp DESC LIMIT 1"));
- $previous_links = mysql_query("SELECT * FROM links WHERE pubdate = '$previous_date[pubdate]' ORDER BY clicks DESC");
- while ($previous_array = mysql_fetch_array($previous_links))
- {
- <display code omitted>
- }
The first line finds the second most recent date by only checking publication dates not equal to (!=) the latest date used above. And in the next section, which I'm not posting, we do the same thing for one day earlier by checking dates not equal to the $latestdate or $previous_date.
And this code puts in a lot of work. The same script is called up on the main Low End Mac home page; our iMac, Power Mac, and 'Book indexes; and at the bottom of a lot of our editorial content. (Eventually all of it, but it's going to take some time to update and upload all those pages.)
I've slightly modified this code for our mobile edition and
WebTV home pages. Best of all, I don't have to manually update all
of these pages 2-3 times daily - the computer is doing it for me
and making my life simpler.
Recent Online Tech Journal Columns
- Optimized Software Builds Bring Out the Best in Your Mac, 06.30. Applications compiled for your Mac's CPU can load more quickly and run faster than ones compiled for universal use.
- Low End Mac's Safe Sleep FAQ, 06.15. What is Safe Sleep mode? Which Macs support it? How can you enable or disable it? And more.
- The Original Macintosh, 01.12. An in-depth look at the original Macintosh and how it shaped future Macs.
- The Innovative Lisa, 01.08. Apple's Lisa and how it paved the way for the Macintosh.
- More in the Online Tech Journal index.
Links for the Day
- Mac of the Day: iMac Core Duo, Jan. 2006 - The first Intel-based iMacs ran at 1.83-2.0 GHz, came with 17" and 20" displays.
- Group of the Day: Mac Pro List is for those using a Mac Pro.
- November 22 in LEM history: 99: Gradebooks - 00: Leveraging Apple design - Quadra 630 to Power Mac 5200 - 02: Laptop or desktop? - 04: SuperDuper: Quick, easy, efficient backup - Cross-platform programming for the rest of us - 05: Mac video surveillance on the cheap - Which OS is best for my vintage Mac? - No 'best browser' for the Mac - Sorry state of browsers for classic Macs - 06: Core 2 means cooler running 'Books - 2.0 GHz G4 upgrade
- Support Low End Mac
Recent Content on Low End Mac
- Apple's Tablet an End Run Beyond Netbooks, Frank Fox, Stop the Noiz, 11.20. Whatever Apple has planned will leverage existing technologies while going beyond what its competitors can offer.
- i5 iMac Benchmarked, Mac mini 'Shouldn't Be Overlooked', Twitter Client for Classic Mac OS, and More, Mac News Review, 11.20. Also why Apple leaves the low end to others, 10.6.2 fixes video playback problem in 27" iMac, 3D Leopard and Snow Leopard performance, and more.
- Apple #4 in Reliability, Apple Tablet a Gadget for All?, HP's i7 Notebook Outdoes Mac Rivals, and More, The 'Book Review, 11.20. Also Flash 10.1 improves video on Hackintosh netbooks, thin-and-light notebooks impress, Windows XP finally on the way out, and more.
- NASA Chemical Sensor for iPhone, Smartphone Death Match, iPhone Earrings, and More, Ian R Campbell, 11.20. Also mobile phone dangers, new apps, GPS solution for iPod touch, new iPod and iPhone cases, and more.
- Replacing the Hard Drive in a Clamshell iBook, John Hatchett, Recycled Computing, 11.19. Yes, it is one of the most difficult Apple notebooks to disassemble and reassemble, but a 10 GB hard drive just will not do.
- IBM Model F: A Great Old Keyboard with an Outdated Layout, Tommy Thomas, Welcome to Macintosh, 11.19. Although it used a different technology than the revered IBM Model M keyboard, the Model F was a great keyboard in its own right.
- Soft Touch Keyboards, Wireless Mouse Options, Loving SeaMonkey 2, and More, Charles W. Moore, Miscellaneous Ramblings, 11.18. Also the future of browsing with PowerPC Macs and the multiple mouse input bug introduced with OS X 10.5.8.
- More links in our archive.
Recent Deals
- Best eMac Deals, 11.18. Used 1 GHz Combo, $100; SuperDrive, $269; 1.25 GHz Combo, $119; SD, $319; 1.42 GHz Combo, $289; SD, $498.
- Best Mac OS X 10.6 and Mac Box Set Deals, 11.18. "Snow Leopard", single user, $25; 5 users, $45; Mac Box Set, single user, $139; 5 users, $180; Server, $414. Shipping included.
- Best Xserve Deals, 11.18. Used 1 GHz dual G4, $649; 2.3 dual G5, $795; 3.0 4-core Xeon, $1,899; refurb 2.26 4-core, $2,499; new, $2,888; refurb 8-core, $2,999; new, $3,449; more.
- Best 15" MacBook Pro Deals, 11.17. Used 1.83 GHz, $750; 2.16, $800; 2.33, $900; refurb 2.4, $1,299; 2.53, $1,449; 2.66, $1,699; 2.8, $1,899; new 2.53, $1,579; 2.66, $1,799; more.
- Best Power Mac G4 and AGP Video Card Deals, 11.17. Used 400 MHz, $50; 933 MHz, $80; 500 dual, $60; 867 dual, $90; 1 GHz dual, $150; 1.25 GHz dual, $225; 1.42 GHz, $499.
- Best Mac OS X 10.5 Deals, 11.17. "Leopard" upgrade, $80; single user license, $135; 5 users, $173; Mac Box Set, 5 users, $230; Server, 10 users, $340; unlimited, $850. Shipping included.
- Best Mac mini Deals, 11.16. Used 1.42 GHz G4 mini, $379; 1.66 GHz Core Solo, $419; 2.0 Core 2, $450; new 2.26 GHz nVidia, $580; 2.53 GHz, $769; Server, $990.
- Best iBook G4 Deals, 11.16. Used 12" 1.07 GHz Combo, $210; 1.33 GHz, $298; 14" 1.33 GHz, $398; 1.42 GHz, $479; SuperDrive, $498.
- Best iPod shuffle Deals, 11.16. Used 1 GB, $35; 4 GB, $65; refurb 1 GB, $39; 2 GB, $59; new 2 GB, $55, 4 GB, $75. New and refurb prices include shipping.
- More deals in our archive.
About LEM | Support | Usage | Privacy | Contacts
Navigation
Used Mac Dealers
Apple History
Video Cards
Email Lists
Favorite Sites
MacSurfer
MacMinute
MacInTouch
MyAppleMenu
InfoMac
Macs Only!
The Mac Observer
Accelerate Your Mac
RetroMacCast
PB Central
MacWindows
The Vintage Mac
Museum
DealMac
DealsOnTheWeb
Mac2Sell
ramseeker
Mac Driver Museum
JAG's House
System
6 Heaven
System 7 Today
the pickle's Low-End
Mac FAQ
Abandonware
Petition
Mac vs. PC Info
Affiliates
The Apple
Store
Mac
Connection
B&H
MacMall
TechRestore
ExperCom
Crucial
Memory
batteries.com
Advertise
MacMinute
MacInTouch
MyAppleMenu
InfoMac
Macs Only!
The Mac Observer
Accelerate Your Mac
RetroMacCast
PB Central
MacWindows
The Vintage Mac
Museum
DealMac
DealsOnTheWeb
Mac2Sell
ramseeker
Mac Driver Museum
JAG's House
System 6 Heaven
System 7 Today
the pickle's Low-End
Mac FAQ
Abandonware
Petition
Mac vs. PC Info
Mac Connection
B&H
MacMall
TechRestore
ExperCom
Crucial Memory
batteries.com
