Jump to content

Add pages with MySQL/PHP CMS?


son

Recommended Posts

This is just a general question: If you were to create a simple CMS system based on MySQL and PHP how can you make it possible to add pages to website? I am able to show/manipulate text on existing pages, but how can you 'add' pages? Son

Link to comment
Share on other sites

I'd probably store the content in a database. The only other way I can think of is to make an actual include file and point to it from the database, but I don't know why anyone would do that...

Link to comment
Share on other sites

I am able to show/manipulate text on existing pages, but how can you 'add' pages?
Use INSERT queries. Then in the menu, you just cycle through the rows in the pages table and print them out.
Link to comment
Share on other sites

Use INSERT queries. Then in the menu, you just cycle through the rows in the pages table and print them out.
Synook,So I create a new record inserting data from my web form with the file name, the heading and text into db. Then on actual pages I loop through the column with filenames, displaying them with the link information. But where is the actual php file I am pointing to? Let's say I inserted a new row as:file name: newheading: New contenttext: This is just some new textHow would I create new.php, so when someone clicks onto new he/she acually would see www.domain.co.uk/new.php? If possible I would not like to have 'real' files with relevant content as opposed to one page, which updates when info from querystring is passed. Is this possible?Son
Link to comment
Share on other sites

Oh. You could create a page, lets call it page.php, and then retrieve the data from the db based on a GET variable. E.g.

<?phpinclude("header.php");//connect to db$result = mysql_query("SELECT * FROM pages WHERE `file name` = '" . mysql_real_escape_string($_GET['page']) . "'");$page = mysql_fetch_assoc($result);echo "<h1>{$page['heading']}</h1>";echo $page['text'];include("footer.php");

Your links will be generated as you iterate with the href being "page.php?page={$page['file name']}", and therefore the link for the new page would be page.php?page=new.

Link to comment
Share on other sites

Oh. You could create a page, lets call it page.php, and then retrieve the data from the db based on a GET variable. E.g.
<?phpinclude("header.php");//connect to db$result = mysql_query("SELECT * FROM pages WHERE `file name` = '" . mysql_real_escape_string($_GET['page']) . "'");$page = mysql_fetch_assoc($result);echo "<h1>{$page['heading']}</h1>";echo $page['text'];include("footer.php");

Your links will be generated as you iterate with the href being "page.php?page={$page['file name']}", and therefore the link for the new page would be page.php?page=new.

Sorry, to be a pain. But is it done when you look at a website and it show behind the last / each time a different file as '/Services.aspx' for example? I know this is not the same technology, so is this the reason why it cannot be done with PHP/MySQL?Son
Link to comment
Share on other sites

Umm... either they are actually creating a different file for each page, and not using a database for the content, or they are using URL rewriting. On an Apache database this could be achieved using Mod_Rewrite - for example, make a new file called .htaccess and put in it

RewriteEngine onRewriteCond %{QUERY_STRING} (.*)RewriteRule ^([a-z0-9]+)\.php$ page.php?page=$1&%1 [L]

Then new.php will be redirected (server-side) to page.php?page=new.

Link to comment
Share on other sites

Umm... either they are actually creating a different file for each page, and not using a database for the content, or they are using URL rewriting. On an Apache database this could be achieved using Mod_Rewrite - for example, make a new file called .htaccess and put in it
RewriteEngine onRewriteCond %{QUERY_STRING} (.*)RewriteRule ^([a-z0-9]+)\.php$ page.php?page=$1&%1 [L]

Then new.php will be redirected (server-side) to page.php?page=new.

I saw it on website where the owner can add files as he wants to and as there is no automation to include info to .htaccess (or at least I believe so) it could not be done with Mod_Rewrite. When you are saying 'they are actually creating a different file for each page': Is this possible and if yes, what is the terms I would need to search for to get some more info on that?Thanks,Son
Link to comment
Share on other sites

I saw it on website where the owner can add files as he wants to and as there is no automation to include info to .htaccess (or at least I believe so) it could not be done with Mod_Rewrite. When you are saying 'they are actually creating a different file for each page': Is this possible and if yes, what is the terms I would need to search for to get some more info on that?Thanks,Son
Actually, just a though: Is it possible with mod_rewrite to erase 'content?id=' out of any url? This would make it look the way I want it (I pass the actual file name)...Son
Link to comment
Share on other sites

mod_rewrite doesn't replace URLs in the browser, it tells the server how to handle a given URL. You format the URL how you want it and then set up mod_rewrite to turn that URL into another one that the server can handle.

Link to comment
Share on other sites

mod_rewrite doesn't replace URLs in the browser, it tells the server how to handle a given URL. You format the URL how you want it and then set up mod_rewrite to turn that URL into another one that the server can handle.
Will have a go, thanks...Son
Link to comment
Share on other sites

I saw it on website where the owner can add files as he wants to and as there is no automation to include info to .htaccess (or at least I believe so) it could not be done with Mod_Rewrite.
.htaccess is just another file, you'd include it in the package with all the other files the owner needs. Because of the Regular Expression in it, mod_rewrite will rewrite all URLs that match, so no new rules need to be added for each page.
When you are saying 'they are actually creating a different file for each page': Is this possible and if yes, what is the terms I would need to search for to get some more info on that?
I meant they used a text editor to actually create a new file with all the content they wanted in it, then saved as "services.aspx".
Link to comment
Share on other sites

.htaccess is just another file, you'd include it in the package with all the other files the owner needs. Because of the Regular Expression in it, mod_rewrite will rewrite all URLs that match, so no new rules need to be added for each page.I meant they used a text editor to actually create a new file with all the content they wanted in it, then saved as "services.aspx".
Thanks for your help:-)Son
Link to comment
Share on other sites

There's also a great article on A List Apart about a modified use of mod_rewrite and PHP that explains another way of doing this. I use it on several of my clients' sites, and I love the results.Link: How to Succeed with URLsHope that helps.-Jason

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...