PHP Archives

Build HTML Tables From MySQL Tables with PHP

Published by David Walsh on Wednesday, July 21, 201011 Comments

I was recently completing a project which required that I build a series of HTML tables which would represent all of the tables within a MySQL database.  I didn’t have anything created but after a few minutes I had exactly what I needed. Hopefully this helps you out!

The CSS

table.db-table 		{ border-right:1px solid #ccc; border-bottom:1px solid #ccc; }
table.db-table th	{ background:#eee; padding:5px; border-left:1px solid #ccc; border-top:1px solid #ccc; }
table.db-table td	{ padding:5px; border-left:1px solid #ccc; border-top:1px solid #ccc; }

The CSS I’m styling the table with is as basic as it gets — style as you wish!

Create a “Recent Posts” Module Outside of WordPress

Published by David Walsh on Friday, April 16, 201031 Comments

The websites I create are never powered by WordPress. Sure I may add a blog to the website but I’ve never created a client website that was run by the powerful blogging software. In an effort to tie the website and blog together, I’ll usually do some quick PHP/MySQL programming to pull in recent blog post titles and links to the individual posts. Here’s the PHP and MySQL that accomplishes that task.

Create Bit.ly Short URLs Using PHP: API Version 3

Published by David Walsh on Thursday, April 8, 201010 Comments

Bit.ly is a great URL shortening service. I love their reliability, shortness of the URL, and the information they provide about a given URL. Recently Bit.ly updated their API to version 3 so I thought I’d update my original Bit.ly post. Here’s how you can create short URLs and expand short URLs using Bit.ly.

iPad Detection Using JavaScript or PHP

Published by David Walsh on Wednesday, April 7, 201019 Comments
iPad

The hottest device out there right now seems to be the iPad. iPad this, iPad that, iPod your mom. I’m underwhelmed with the device but that doesn’t mean I shouldn’t try to account for such devices on the websites I create. In Apple’s developer tip sheet they provide the iPad’s user agent string:

Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10

Given that string we can create a few code snippets to determine if the user is being a smug, iPad-using bastard.

Automatically Generate a Photo Gallery from a Directory of Images: Updated

Published by David Walsh on Tuesday, April 6, 201050 Comments
PHP Photo Gallery

Two years ago Chris Coyier wrote an outstanding tutorial detailing how you can generate a photo gallery based on the images within two directories: a thumbnails directory and an originals directory. I’ve decided to take his tutorial a step further by showing you how to generate thumbnails for the gallery using PHP. I’ve also implemented a MooTools lightbox: Smoothbox. The following code will show you how to create a beautiful photo gallery by simply dumping your photos in a directory.





© David Walsh 2007-2010. Contact David Walsh. Powered by the remarkable MooTools JavaScript framework.