Classified Action
By Ray Argus
Ideally, data-driven Web sites should let you separate content from presentation. Authors should create content without regard to how it will be displayed, letting designers manage the actual appearance of the page elements. But what happens when anyone with access to your site can create content?
Recently, a client asked me to build a classified ad system using PHP. The system needed to let users place their own ads online. But because that invites spam and other mischief, an administrator would have to approve the ads (after possibly processing a credit card for payment).
The system I devised can integrate with the PHP shopping cart that appeared in the November 2000 Web Techniques "Script Junkie" column I wrote with Jerid Freeland.
What's In an Ad?
To represent an ad, I created a database table. Each row contains one ad. Here are the fields:
catid. The category ID (each ad is, of course, in a classification).
adid. A unique ID for the ad (an auto increment or identity field).
exp. The expiration date and time of the ad.
title. The ad's title.
text. The main text of the ad (as a blob field).
response. The advertiser's email address.
graphicurl. An optional image to post with the ad.
posted. The posted time and date.
active. Set to 1 if the ad is approved for display.<>