Dynamic Website Content

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Dynamic Website Content

Post by jayshields »

I'm just about to start a new project.

I'm wondering how to design it as it will have dynamic content.

Usually I would just make a header and footer html file of the design and for each page make a new php page and include the header and footer and put the content in the middle.

This time I want every page to be manageable from the admin panel. It would be easy if the pages were just static information but I want some/all of the pages to contain functionality via PHP. Also, my design can have mutliple content boxes, so I'm also wondering how to manage that. I was thinking maybe I could structure the table like so: page_ID, page_name, page_content1, page_content2, page_content3 - but that would limit the amount of content boxes available to use to 3.

So I was thinking would it be a good idea to allow the administrator to use some sort of custom tag to start and finish content blocks? like

Code: Select all

<content>
  <title>A title</title>
  whatever
</content>
<content>
  <title>A different title</title>
  whatever else
</content>
and then just structure the table like so: page_ID, page_name, page_content.

Or should I just set let the administrator use the html the same as in my design? like

Code: Select all

<div class="content">
   <h3>:: Flanking Menus</h3>
   <p>With the popularity of three column layouts, this layout is bound to be useful to many. You may have seen this technique used at <a href="http://www.wrongwaygoback.com/" title="wrongwaygoback">dynamic ribbon device</a>. In fact, this "flanking menus" technique was devised by BlueRobot for that site. Surprisingly, the technique has caused quite a bit of talk. The concept is simple: a content box with large margins is flanked by two additional (menu) boxes.</p>
   <p>An important benefit of this technique is the order of elements in the HTML source. Here, the order is essentially content, menu one, menu two. For old browsers, text-only browsers, screen-readers, and many alternative devices, this means that the content is displayed before the menus. And, after all, most users visit a page for its content.</p>
</div>
I think the second option is the most practical, but I'm wondering how you guys would tackle this problem?

Also, how would I go about implementing the second option? Would I just have to use str_replace alot?

Thanks :)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I just wrote a hella long reply to re-reread your question and realize I had it wrong :oops:

What I would generally do is have 2 tables
table: pages
pageid, pagename, permission (?)

table: content
pageid, contentid, content
so each new "content block" has its own row in the content table, associating through `pageid` and using a join to combine them

Code: Select all

$sql = '
   SELECT `pages`.`pagename`, `content`.`content`
   FROM `pages` 
   INNER JOIN `content` USING (`pageid`)
   WHERE `pages`.`pageid` = \''.mysql_real_escape_string($requestedPage).'\'';
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

Hehe.

I've been working on my database structure for this all afternoon and I have come up with the exact same idea as you.

Here's my structure:

Code: Select all

-- 
-- Table structure for table `content`
-- 

CREATE TABLE `content` (
  `content_id` int(11) NOT NULL auto_increment,
  `page_id` int(11) NOT NULL default '0',
  `title` varchar(30) NOT NULL default '',
  `body` mediumtext NOT NULL,
  `weight` int(11) NOT NULL default '0',
  PRIMARY KEY  (`content_id`),
  UNIQUE KEY `weight` (`weight`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

-- 
-- Table structure for table `pages`
-- 

CREATE TABLE `pages` (
  `page_id` int(11) NOT NULL auto_increment,
  `name` varchar(30) NOT NULL default '',
  `note` varchar(80) NOT NULL default '',
  `weight` int(11) NOT NULL default '0',
  `views` int(11) NOT NULL default '0',
  `date` datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`page_id`),
  UNIQUE KEY `weight` (`weight`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;
lol, I even used the same table names as you 8O.

I'm still wondering how to do the administration of the content though. I think my second proposed option would be best, I'm going to have to put up with excessive str_replace usage though :(
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

What problems are you having with the adminstrative section??
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

None yet, I'm just thinking ahead.

I thought it would be too time consuming to use str_replace excessively to replace custom tags with HTML tags for the content sections, but now I've come to think about it, with this table structure the admin won't have to handle any tags what-so-ever.

I'm just working on the display page script now :)
Post Reply