Rommeo Posted December 29, 2007 Share Posted December 29, 2007 Hi i m new at php programming.. I have a question about creating static pages. What i want to do is ; instead of creating web pages like " aboutus.php " .. ( www.mywebsite.com/aboutus.php ) i want to store that page in Mysql, then i wanna reach it by entering " www.mywebsite.com/?page=aboutus " So does this way have a name ? I ll be glad if you can tell me the way to do this ?-or you can give me the link if there is any tutorial about this ( i could not find any ).. Thanx in advance -- lets say i have stored a page ( title / content /time ) in mysql and i wanna give the link from my index.php page. will it be something like : <p><a href="<?php $pagename="aboutus" ?>">about us</a></p> then how can i take this page and display it :S Quote Link to comment https://forums.phpfreaks.com/topic/83628-static-pages-in-mysql/ Share on other sites More sharing options...
revraz Posted December 29, 2007 Share Posted December 29, 2007 You can still have a page called www.mywebsite.com/aboutus.php that reads from a database. I don't really see the point of doing it part of your index.php. But if you really wanted to, use index.php?aboutus=yes and then check it with $_GET['aboutus']="yes" then display DB entry. Quote Link to comment https://forums.phpfreaks.com/topic/83628-static-pages-in-mysql/#findComment-425419 Share on other sites More sharing options...
Rommeo Posted December 29, 2007 Author Share Posted December 29, 2007 sorry i m a newbie, index.php?aboutus=yes What is this yes for ? and i wanna do this cause i dont wanna create a lot of pages. i just wanna store them in db, then it would be easier to control the whole page, otherwise when you need to delete a web page you 'll need to delete it from db and "aboutus.php " .if i m not wrong ? Quote Link to comment https://forums.phpfreaks.com/topic/83628-static-pages-in-mysql/#findComment-425427 Share on other sites More sharing options...
atlanta Posted December 29, 2007 Share Posted December 29, 2007 You would enter <p><a href="index.php?page=aboutus">about us</a></p> just like that Quote Link to comment https://forums.phpfreaks.com/topic/83628-static-pages-in-mysql/#findComment-425434 Share on other sites More sharing options...
Rommeo Posted December 29, 2007 Author Share Posted December 29, 2007 sorry again ; i m really at the beginning of this programming language. So this time ; <p><a href="index.php?page=aboutus">about us</a></p> i think this "page"(page=aboutus) is the field of the "table_pages" in mysql ? right ? -- i have a table that's name is " table_pages" and i have a field there named " pagename " i also have a variable named " $pagename" in my index.php Quote Link to comment https://forums.phpfreaks.com/topic/83628-static-pages-in-mysql/#findComment-425446 Share on other sites More sharing options...
atlanta Posted December 29, 2007 Share Posted December 29, 2007 post all of your code!. Quote Link to comment https://forums.phpfreaks.com/topic/83628-static-pages-in-mysql/#findComment-425449 Share on other sites More sharing options...
MadTechie Posted December 29, 2007 Share Posted December 29, 2007 okay lets see if i can explain this:~ before we get into the MySQL side of things lets look at $_GET, when you URL contains a ? your passing parameters, ie index.php?page=about so if you create a page called index.php containing the following script <?php echo $_GET['page']; ?> you can load up the page like this index.php?page=Anything Anything index.php?page=you you index.php?page=want want Now when it comes to MySQL.. Just say you have a table called `MyTable` and 2 fields `Title` and `contents` your use a query like this $query = "SELECT contents FROM MyTable WHERE Title = '".$_GET['page']."';" <?php $conn = mysql_connect("localhost", "mysql_user", "mysql_password"); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db("mydbname")) { echo "Unable to select mydbname: " . mysql_error(); exit; } $query = "SELECT contents FROM MyTable WHERE Title = '".$_GET['page']."';" $result = mysql_query($query); if (mysql_num_rows($result) == 0) { echo "Title Not Found"; exit; } $row = mysql_fetch_assoc($result) echo $row['contents']; ?> Please note this is untested EDIT: opps updated SQL Quote Link to comment https://forums.phpfreaks.com/topic/83628-static-pages-in-mysql/#findComment-425450 Share on other sites More sharing options...
Rommeo Posted December 29, 2007 Author Share Posted December 29, 2007 MadTechie That's a great explanation! Thank you ! i ll try to do it now, will post the results. atlanta : Actually i have not coded that much. i was trying these : <form method="post" action="page.php"> <p><a href="<?php $pagename="aboutus"; ?>">about us</a></p> <p><p><a href="<?php $pagename="contact"; ?>">contact</a></p></p> </form> btw is "POST" function has also a feature like this ? ( index.php?page=Anything ) Quote Link to comment https://forums.phpfreaks.com/topic/83628-static-pages-in-mysql/#findComment-425453 Share on other sites More sharing options...
MadTechie Posted December 29, 2007 Share Posted December 29, 2007 No POST is used from a form via the submit button but on the PHP side its the same idea $_POST['Page'] EDIT:typo Quote Link to comment https://forums.phpfreaks.com/topic/83628-static-pages-in-mysql/#findComment-425461 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.