Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/83628-static-pages-in-mysql/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/83628-static-pages-in-mysql/#findComment-425419
Share on other sites

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 ?

Link to comment
https://forums.phpfreaks.com/topic/83628-static-pages-in-mysql/#findComment-425427
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/83628-static-pages-in-mysql/#findComment-425446
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/83628-static-pages-in-mysql/#findComment-425450
Share on other sites

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 )

Link to comment
https://forums.phpfreaks.com/topic/83628-static-pages-in-mysql/#findComment-425453
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.