adam291086 Posted November 8, 2007 Share Posted November 8, 2007 Hello, i am currently planning a new content management system, a very simple one for a uni project. I plan to have the page content and links called from a database using mysql and php. The problem is how to create a new page?? This will have to automatically update the links on all pages. Which wont be hard as to get the links i can set up each page to automaically select * from the links table. But how do i create a new page in the first place and populate it with the correct content. I just need some ideas so help get me started. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/76496-solved-create-a-new-page/ Share on other sites More sharing options...
Perad Posted November 8, 2007 Share Posted November 8, 2007 site.com/index.php?page=contact if ($_GET['page'] == contact) { // Add PHP for contact page here. } Quote Link to comment https://forums.phpfreaks.com/topic/76496-solved-create-a-new-page/#findComment-387452 Share on other sites More sharing options...
adam291086 Posted November 8, 2007 Author Share Posted November 8, 2007 ok i can see that you getting the in info from the url but how do i set the page url to do that. Sorry i haven't much experience in php. Quote Link to comment https://forums.phpfreaks.com/topic/76496-solved-create-a-new-page/#findComment-387453 Share on other sites More sharing options...
~n[EO]n~ Posted November 8, 2007 Share Posted November 8, 2007 Just mouse over on this forums navigation (on the links above) you will see how the value is being passed http://www.phpfreaks.com/forums/index.php?action=help http://www.phpfreaks.com/forums/index.php?action=search http://www.phpfreaks.com/forums/index.php?action=profile like this and you can do like Perad's post above if ($_GET['action'] == help) { // Add PHP for help page here. } Quote Link to comment https://forums.phpfreaks.com/topic/76496-solved-create-a-new-page/#findComment-387459 Share on other sites More sharing options...
adam291086 Posted November 8, 2007 Author Share Posted November 8, 2007 ok, the problem is what if the user add a new page. How will this code automatically change to get the content of the new page? Also how would i go about creating a new page? I think i am trying something out of my legue Quote Link to comment https://forums.phpfreaks.com/topic/76496-solved-create-a-new-page/#findComment-387461 Share on other sites More sharing options...
Perad Posted November 8, 2007 Share Posted November 8, 2007 Its not out of your league, it just needs some more thought. Lets say the user wants to add a new page. The page contains a title and some content. Database Table called pages The user enters page title and content which is stored into the pages table. $title = escape_string($_GET['page']); $sql = "SELECT * FROM pages WHERE title='$title'"; $result = mysql_query($sql); if (mysql_fetch_rows($result) != 0) { $title = $row['title']; $content = $row['content']; } The above code can be improved but you should get the idea. Quote Link to comment https://forums.phpfreaks.com/topic/76496-solved-create-a-new-page/#findComment-387463 Share on other sites More sharing options...
adam291086 Posted November 8, 2007 Author Share Posted November 8, 2007 yeah i have the idea now. Only two more questions 1) How the hell will i create a function to create a new page. I.e with the basic css template done and links added. 2) How do i set the URL to say www.john.com/page=news Quote Link to comment https://forums.phpfreaks.com/topic/76496-solved-create-a-new-page/#findComment-387465 Share on other sites More sharing options...
MadTechie Posted November 8, 2007 Share Posted November 8, 2007 you could do something like this <?php $result= mysql_query("SELECT pagedata FROM pages WHERE name = '{$_GET['page']}'"); if (mysql_num_rows($result) == 0) { echo "No page found"; exit; } $row = mysql_fetch_assoc($result); echo $row['pagedata']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/76496-solved-create-a-new-page/#findComment-387466 Share on other sites More sharing options...
Perad Posted November 8, 2007 Share Posted November 8, 2007 yeah i have the idea now. Only two more questions 1) How the hell will i create a function to create a new page. I.e with the basic css template done and links added. 2) How do i set the URL to say www.john.com/page=news 1) You could use something like Smarty. Smarty allows you to create HTML templates then assign php variables to the template. This allows you to create clean and structured and code. If you do not want to do that then create a new file. page.php page.php should be a html page. Instead of having the title and content you would have <?php $title ?> and <?php $content ?> After you have called the data from the database and assigned them to $title and $content variables you can include the page.php which will then assign the variables to the page.php file. 2) Here is one way. After executing this code you can just print out the array where you need it. // Get title from database while ($row = mysql_fetch_assoc($result) { $navigationarray[] = '<a href="index.php?page=$row['title']">$row['title']</a>'; } Quote Link to comment https://forums.phpfreaks.com/topic/76496-solved-create-a-new-page/#findComment-387480 Share on other sites More sharing options...
adam291086 Posted November 8, 2007 Author Share Posted November 8, 2007 thanks that really helpfull. One more thing then thats it. I see how to make a new page. But how would i go about creating a button that a user can click and a new page is automatically created? By created i mean a blank page showinging the basic page without any content. Then they enter in the conent through the form and the page is then populate with some information. take page.php for example. To get the content it will be using an page ID to search the database for the content and will get page id from the url. How can i get this blank page created? This may be a little confusing. Quote Link to comment https://forums.phpfreaks.com/topic/76496-solved-create-a-new-page/#findComment-387489 Share on other sites More sharing options...
trq Posted November 8, 2007 Share Posted November 8, 2007 Your missing the whole point. The pages don't actually exist! This is the entire point of a dynamic website. Do you think every time a new thread is started on this forum a new page is created? You simply make a page with the forms to fill out, the user fills in the forms hits submit and the data is inserted into the database. To view the page you then call a view.php file and pass it the id through the url. Quote Link to comment https://forums.phpfreaks.com/topic/76496-solved-create-a-new-page/#findComment-387490 Share on other sites More sharing options...
adam291086 Posted November 8, 2007 Author Share Posted November 8, 2007 that explains it. SORRY for being a tit. HAHAHA i now know how this is going to work. I was looking into this far to much. Thanks Sooooooooooooo much you guys. Means that 1st in my degree is getting closer Quote Link to comment https://forums.phpfreaks.com/topic/76496-solved-create-a-new-page/#findComment-387492 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.