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
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
Displaying External Links with PHP
Website Automation with PHP and MySQL, Part 10
Dan Knight - 2002.06.26
In the last article, we looked at the ten fields necessary to make an "external links" database work the way we want it to. This article looks at the programming necessary to display that data properly.
The first thing is to punctuate our display with commas, spaces, and periods. There's a space after the flag; a comma and space after the link, the author, the column title, and the site name; and a period and space after the date.
In our earlier projects, we didn't worry about empty fields in a record, but this time we have to. Here's why: Our standard link entry looks like this:
Rights: Canada bans Mac
use on Internet, Joe Who, Tech Time, Ottawa Ragsheet, 06.25.
After voting to move the nation's capitol to Redmond, WA,
Parliament has banned use of Macs on the Internet inside
Canada.
While every article has a category, a URL, the text that links that URL, a date, and a description, some don't display a flag, have a known author, have a column heading, or sometimes even really have a website. If we hadn't taken that into consideration, the above link could look like this with a few empty fields:
- Rights: Canada bans Mac use on Internet, , , Ottawa Ragsheet, 06.25. After voting to move the nation's capitol to Redmond, WA, Parliament has banned use of Macs on the Internet inside Canada.
That just doesn't look good. So for the first time, I had to wade into using the if command in PHP. Here's the code I created so the above would display properly:
<?php
$db_server = "server.com";
$db_username = "username";
$db_password = "password";
$db_name = "db_name";
$connection = @mysql_connect($db_server,$db_username,$db_password);
mysql_select_db($db_name,$connection);
echo "<ul>";
$get_links = mysql_query("SELECT * FROM xlinks ORDER BY timestamp DESC LIMIT 24");
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 "$array[category]:
<a href=\"$array[URL]\">$array[linktext]</a>, ";
if ($array[author]<>"")
{echo"$array[author], ";}
if ($array[columntitle]<>"")
{echo"$array[columntitle], ";}
echo "$array[website],
$array[pubdate].
$array[description]</li>";
}
echo "</ul>";
?>
The first and last echo statements define the start and end of an unnumbered (bullet) list. That's simple HTML.
The line starting with $get_links tells the server to access the xlinks database and select the 24 records with the most recent timestamps. The next line sets up a loop that repeats up to 24 times to display our external links.
echo "<li>"; starts our bullet list entry - and we immediately run into a field that may be empty. Since most of our linked stories are not of interest to just one nation, we don't often use the flag, but when we do, it comes first.
This is where I learned by trial and error just how the if statement works. It's not hard, but as with all things PHP, you have to get it just right to make it work.
First we test whether the flag field is empty with if ($array[flag]<>""). If it is empty, PHP skips the rest of this command. If not, it displays the flag GIF from our /art directory followed by a space.
Next it links the text to the URL, displays it, and follows it with a comma and space. Then we have two more if statements, one for the author and one for the column title.
After this comes the name of the website, a comma, a space, and the date. Then comes the description of the article or a relevant quote from it.
We've decided that in the case of personal sites (such as mac.com), we'll skip the author field and put the author in the website field. That keeps the code from getting even messier.
And after much trial and error, it looks just beautiful -
exactly like the links we used to craft by hand, but now done
automatically by a computer. And isn't that why computers were
created in the first place?
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: 17" MacBook Pro Core Duo, Apr. 2006 - The top-end MacBook Pro includes a 1680 x 1050, 2.16 GHz Core Duo CPU, and supports Apple 30" Cinema Display.
- Group of the Day: G4 List is for those using Power Mac G4s or G4 upgrades.
- Support Low End Mac
Recent Content on Low End Mac
- Pismo WiFi Networking Issue Finally Solved?, Charles W. Moore, Miscellaneous Ramblings, 11.24. It turns out the problems wasn't the Pismo, the Buffalo WiFi card, or Mac OS X 10.4. It was the Wireless G router - Linksys to the rescue!
- Mini VGA to S-video Adapter a No Go for eMacs, Dan Bashur, Apple, Tech, and Gaming, 11.24. You might think that Apple's Mini VGA S-video adapter is a cheap way to connect your eMac or G4 iMac to your TV. You would be wrong.
- Google Calendar with iPhone or iTouch Is Great for Scheduling, John Hatchett, Recycled Computing, 11.24. Web-based Google Calendar allows access and updates from any computing platform, including Mac, Windows, Linux, and iPhone OS.
- Why Spaces is My Favorite Leopard (and Snow Leopard) Feature, Charles W. Moore, Miscellaneous Ramblings, 11.23. Spaces, a feature introduced with OS X 10.5, is like having several monitors on your Mac without the cost and space of using multiple displays.
- 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'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.
- 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.
- More links in our archive.
Recent Deals
- Best G4 iMac Deals, 11.24. Used 15" 700 MHz CD-RW, $150; 800 MHz Combo, $229; 1 GHz, $289; 17" 1.25 GHz, $200; 20" 1.25 GHz, $509.
- Best MacBook Air Deals, 11.24. Used from $899; refurb from $1,099; new 1.6 GHz/120 HD, $1,150 after rebate; 1.8/64 SSD, $1,150 a/r; 1.86/128 SSD, $1,350 a/r; 2.13/128 SSD, $1,694 a/r.
- Best PowerBook G3 Deals, 11.24. Used 233 MHz WallStreet, $75; 266 MHz, $160; 400 MHz Lombard, $199; 400 MHz Pismo, $289; 500 MHz, $350.
- Best 12" PowerBook G4 Deals, 11.23. Used 867 MHz SuperDrive, $348; 1 GHz Combo, $379; SD, $519; 1.33 GHz, $529; 1.5 GHz Combo, $549; SuperDrive, $609.
- Best Mac Pro Deals, 11.23. Used 2.66 GHz 4-core, $1,300; 3.0 4-core. $1,919; refurb 2.66 4-core Nehalem, $2,149; 2.93, $2,549; 2.93 8-core, $4,999; new 2.26 8-core, $2,290.
- Best Time Capsule and AirPort Deals, 11.23. Used 802.11g AirPort Extreme, $49; 500 GB Time Capsule, $150; new, $190; 1 TB dual-band, $280; 2 TB, $469; 802.11n AirPort Extreme, $170.
- 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.
- 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
