hey all -

I'm more of a self-taught programmer but am going to school for programming as well. I'm quickly finding out that my favorite languages are the ones that school doesn't teach. figures, doesn't it?

anyways, I've been playing with php/mysql for around a year now, and have been gradually trying to design harder algorithms. Eventually I want to try and code a fully functional CMS, and have a good idea how to go about most of it, however, there is one issue that has me a little stuck.

I have 2 scripts running so far, one will allow a user to add a page (which includes the page title and the content of the page, and automatically assigns a page id - auto-increment, of course) and the other script will allow a user to edit a specific page.

all page content is stored in a mysql database in a table called pages. it consists of pageID, pageTitle, and pageContent.

what I'm trying to do is pull the pageTitle column from the database and into a dynamic menu, that will add/remove/change links according to what the user does with the page titles/pages themselves.

I can retrieve the page titles just fine, but my big question is, how would I work this so the user can click on the page title and the content will display either in a new page (probably using frames) or, preferrably, the same page?

I am able to assign the page title's name as a link - so main.php shows up as

<a href="main.php">main</a>

so ideally the user would click on a menu item, and the site goes to that page - I have everything stored on the mysql database, however, so technically I don't really have a main.php or about.php, etc.

would I have to dump the contents of the row into a temporary file and give it the name of the link the user clicks on or is there some other way I should go about this?

PHP sits behind your web server. If a page does not exist on the web server, then PHP will never be invoked.

For example, your page main.php doesn't exist, so PHP never gets executed.

Most CMSs will have just one entry page. Usually it is the index.php page, at the root of the CMS. This page handles all requests, and delegates the requested actions to to other PHP pages, or classes/functions etc.

You'll want to look into the MVC design pattern if you develop a CMS.

http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller

You can implement your own pattern, but you want to know how people are doing it now, so you can do it better.

The only way you can retrieve a page, is by its unique ID. You can use the title if you implement uniqueness in the title.

So to retrieve a page, would look like:

index.php?page=$pageid;

Now you can get that to look like

/page/$pageid

By configuring your web server to map /page/id to index.php?page=$pageid

You can also use the title, or a combination of title and ID.

eg:

index.php?page=$title -> /page/$title
index.php?page=$id:$title -> /page/$id:$title etc.

or:

index.php?page=$title -> /$title
index.php?page=$id:$title -> /$id:$title etc.

To do this you need URL rewriting. Most web servers can map URLs based on regular expressions, to another URL. Apache uses mod_rewrite for this.

http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html

If you use a MVC pattern, it is easier to implement URL rewriting in your CMS. The reason is that each action is routed independently of what it does. So you have a central part of your CMS that does routing, and can also handle URL rewriting.

if you want to create dynamic links without php page existence in real but dynamically. see this thread, here is an attachment example, try that in your server. that will help you how to create dynamic php pages and how to do URL rewriting

http://www.daniweb.com/forums/thread186889.html

you guys are awesome - thank u very much :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.