Probably simple, but need help [PHP, MySQL]

GJSNeptune

[H]F Junkie
Joined
Mar 31, 2004
Messages
12,372
First, I want to compile into one list the most recently submitted items from multiple tables. For example, a list of the last five items I've put into the database, whether they're blog entries, pictures (or a gallery), a song, or a writing piece. Right now blog entries are stored in one table, and writing pieces in another. I haven't created tables for music or pictures yet.

Second, I want these items to be listed as mod_rewrite-friendly links, such as http://www.domain.com/$section/$title. However, I can't think of how I'd determine $section without making it a field in each table. Seems silly to do just to make links easier to do. I have a type field in the writing table because it contains poems, fiction, and nonfiction, but for blog entries, music, and pictures, I'm stumped.

The easy way to do this is to simply display results under their respective categories, but that means more text (and clutter) in the div. I really want to see if I can do it better.

Hope I explained it clearly. Suggestions?
 
It looks like you're writing a CMS from scratch...

The Drupal solution is to make all content is a 'node' - this is where common info like title, author, publication date, etc. is stored. Each specific type of content is then linked to the base node record.
 
Yep. But can you be a bit more specific about this node method?

Download Drupal and take a look.

There are 100x different ways to complete the task you have outlined. Try picking one, start programming it, and ask specific questions as you run into problems.
 
Yep. But can you be a bit more specific about this node method?

You'd have a 'node' record for every piece of content that contains basic info that will be on anything, give it a unique ID and a 'type'. Each type has its own table that contains type-specific data and references the node id.
 
Query the tables you want to display data for and sort so that the highest ID # are first, and then LIMIT 5. Now you have the 5 most recent per-table.

You could do something similar by storing your items in 1 table, and then defining with a column what type of item it is. Then selecting the TOP 5 would return a mix of what you recently put in, and not 5 from each category.

I think you mean search engine friendly URLs utilizing mod_rewrite to parse them?

If you have 5 sections, and 5 queries (1 for each section) you could use a static section name, something like yoursite.com/section-name/id#(or title cleaned up). And then utilize mod_rewrite in .htaccess to tell php to load the correct data. PHP would then look at section-name determine which table to select the article/pic/etc from, and then display it based on the id#/title.

I hope that helps some.
 
I already have the mod_rewrite rules in place. The query and PHP have to know which section the item came from to form the URL, and that's where I'm stuck. The easiest solution is probably putting a type in each table.

I'll try the ID thing.
 
Back
Top