Counting Clicks with PHP and MySQL
Website Automation with PHP and MySQL, Part 11
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: NewerTech NuPower Batteries for iBook and PowerBooks Designed+Built in USA to run longer, LAST LONGER TOO! Free Battery Recycling Return Label; Quality High-Capacity from $99.95
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.06.28
Last week we created our database for external links and figured out how to display these links even when fields were empty, as covered in Part 9 and Part 10 of this series. Now we take things a step further.
I've been including external links on the Low End Mac home page since April 1997, the month I began the site. In all these years, I've had no way of knowing how often visitors to the site follow those links or which links have been the most popular.
Working with PHP and MySQL to manage external links, I now have the opportunity to track how many times a link is clicked. I'll be able to use that information to better understand what visitors to the site find interesting.
Counting Clicks
The first step in counting clicks was creating a PHP script that would use the unique ID of each record in our database, increment the count for that record, and then open the desired page. Here's the core of that code:
$array = mysql_fetch_array(mysql_query("SELECT URL,clicks FROM xlinks WHERE ID='$id'"));
$clicks = $array[clicks] + 1;
mysql_query("UPDATE xlinks SET clicks='$clicks' WHERE ID='$id'");
header("Location: $array[URL]");
This finds record X in the xlinks (external links) database, reads the URL and number of clicks, adds one to the click count, and then opens the desired page with the last line of code.
Of course, this means we have to go back and modify our display code so that it calls up this PHP script (portal.php) instead of leading directly to the external page. Where the earlier script contained this line:
<a href=\"$array[URL]\">$array[linktext]</a>, ";
the revised script reads thus:
<a href=\"/scripts/portal.php?id=$array[ID]\">$array[linktext]</a>, ";
When I click on a link, it quickly calls up the portal script, increments the count, and launches the desired page. It happens so fast that you'll probably never notice the difference, but now I'll be able to track how often these external links are followed.
Learned From Tracking Clicks
Since implementing this system, we've posted 60 external links. The most clicked outside article was Crouching Apple, hidden "Jaguar" on Extreme Tech, which received 438 visits due to our link. Right behind it was A battle PC giants should lose on osOpinion at 347.
The least clicked external link was Apache anti-hack patch posted, which was only relevant to those running their own servers on OS X or some other flavor of Unix, with 27 clicks.
Overall, we're typically seeing 60-200 clicks to the articles we link to. After all these year, it's nice to know how often these links are being used.
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: iMac G5 (iSight), Oct. 2005 -Apple built an iSight webcam into the last version of the G5 iMac.
- List of the Day: Leopard List Low End Mac's email list covering Mac OS X 10.5.
- October 12 in LEM history: 98: Beyond HFS+ nightmares - 99: iMacs for all - 00: The future of low-end gaming - 01: Tips on buying a new computer - 05: iMac G5 (iSight) - Simple backup strategies - 06: Bring back flexible, easy to upgrade 'Books - 07: Road Apple nominations - PB 150 boots from Compact Flash - Leopard to slow down PowerPC Macs?
Recent Content on Low End Mac
- TruePower Battery Can Run WallStreet PowerBook Past the 5 Hour Mark, Tommy Thomas, Welcome to Macintosh, 10.10. If you have a rugged old PowerBook but its battery is losing capacity, TruePower can give you plenty of time in the field.
- nVidia Inside Next MacBook?, Time for a Mac Netbook, Asus Launched MacBook Air Killer, and More, The 'Book Review, 10.10. Also photo reveals more about MacBook Pro, comparing 16:9 and 16:10 displays, Apple settles suit over faulty iBook and PowerBook adapters, bargain 'Books from $150 to $2,699, and more.
- 30% of iPhone 3G Buyers Switched Carriers, EU Battery Rule May Force iPhone Redesign, and More, iNews Review, 10.10. Also iPhone 3G greatest consumer electronics device ever, track presidential polls on your iPhone, Talking English Dictionary, waterproof armbands, several new iPhone apps, and more.
- Economic Crunch May Slow Mac Sales, a Recycled Cube, ToCA Race Driver 3 for Mac, and More, Mac News Review, 10.10. Also don't buy RAM from Apple, customize your Mac's appearance, MacTribe expanding into print, My Apple Space social networking, and more.
- Best Mac Pro Deals, Low End Mac Deals, 10.10. Used 2.66 GHz 4-core, $1,799; new, $1,949 after rebate; 2.8 4-core, $2,099 shipped; 8-core, $2,599 shipped; 3.0 $3,399 shipped; 3.2, $4,099 shipped.
- Best PowerBook G3 Deals, Low End Mac Deals, 10.10. Used 14" WallStreet G3/266 MHz, $90; Lombard G3/400 MHz, $150; Pismo G3/400 MHz, $300; 500 MHz, $350.
- Best Time Capsule and AirPort Deals, Low End Mac Deals, 10.10. Refurb 500 GB Time Capsule, $249; new, $294; refurb 1 TB, $419; new, $462; AirPort Extreme Card, $39; Base Station, $159; Express, $60.
- Modding Your Old Mac to Make It More Useful, Phil Herlihy, The Usefulness Equation, 10.09. If your old Mac is too slow, too noisy, too plain looking, or has too little room for expansion, you might want to mod it.
- What Would an $800 MacBook Mean for the Mac mini?, Dan Knight, Mac Musings, 10.09. If Apple does release an $800 entry-level MacBook next week, the $600 Mac mini is going to look very overpriced.
- Best iMac G4 Deals, Low End Mac Deals, 10.09. Used 15" 700 MHz CD-RW, $269; 800 Combo, $300; 1 GHz, $390; 17" 1.25 GHz SuperDrive, $400; 20", $529.
- Best 15" MacBook Pro Deals, Low End Mac Deals, 10.09. Used 1.83 GHz Core Duo, $995; 2.16, $1,125; new, 2.2, $1,400 after rebate; refurb 2.4, $1,699; 2.5, $1,999; 2.6, $2,299; rebates on new.
- Best Mac OS X 10.4 'Tiger' Deals, Low End Mac Deals, 10.09. DVD upgrade from 10.3, $75; upgrade bundle with 10.3, $118; full version, $129; family pack, $200; 10-user Server, $350; unlimited, $400.
- The Power of Older Macs, Why Vista Only Sees 3 GB of RAM, Wangwriter Supplies, and More, Charles W. Moore, Miscellaneous Ramblings, 10.08. Also the end of an era as MIT HyperArchive shuts down and another suggestion for profiling Windows computers.
- Migrating My Law Office from Windows to Macintosh, Andrew J Fishkin, Best Tools for the Job, 10.08. By switching to Leopard Server, everyone in the office will be able to move to a Mac - but which ones will best meet their needs?
- Low End Mac Needs Help Moving to Joomla, Dan Knight, Mac Musings, 10.08. We've settled on Joomla as the content management system that should work very well for Low End Mac, but we're running stuck with templates.
- Will Apple's iPhone/App Store Tornado Blow Away the Competition?, Tim Nash, Taking Back the Market, 10.08. The iPod, iTunes, and the iTunes Store paved the way for the success of the iPhone and the App Store - and nobody can match that.
- More links in our archive.
Go to the Online Tech Journal index.
About LEM | Support | Usage | Privacy | Contacts

