MYSQL? PHP?, I am so lost... |
![]() ![]() |
MYSQL? PHP?, I am so lost... |
May 7 2008, 07:35 PM
Post
#1
|
|
|
Member ![]() ![]() Posts: 44 OS: XP |
I know that I could use SSI, but I have heard that is slows down the loading of pages and such. I have read a few books on PHP and MYSQL, and I understand the basic code, but I need help on how it is put into use. Like I have noticed on some sites, after the document or page it has something like this: CODE ?page=content/page I just don't get how to do things like that, for example: creating a page that when I change the top or the colors, that it will change everything. How do major websites like Digg or even this one code their websites? Do they code each portion with html or php and put it in the database or is the database even in effect or helping with the design at all? I need someone to help me with this. If you guys could find me a script or just explain it to me, it would help tons. Thanks This post has been edited by Mr. Jack: May 7 2008, 07:38 PM |
|
|
May 9 2008, 12:48 PM
Post
#2
|
|
|
Spyware Veteran Posts: 20,730 From: Netherlands OS: XP Pro & Vista Ultimate |
To style your site different pages at once, the easiest to use, at least in my opinion is a stylesheet.
A good place to start studying how these css stylesheets work is http://www.w3schools.com/Css/default.asp Also worth a visit: http://www.echoecho.com/css.htm http://www.w3.org/Style/Examples/011/firstcss I hope this helps you on your way. |
|
|
Jun 18 2008, 08:18 AM
Post
#3
|
|
|
New Member ![]() Posts: 3 OS: XP |
CSS is the best way to make simple updates to changes like color or layout. If you are wanting to make site wide changes to a certain part (like navigation links or a header/footer) I would recomend creating that in a seperate file and using include('file.php'). That way you can change 'file.php' and the changes will show on all of your pages.
|
|
|
Jun 21 2008, 06:04 AM
Post
#4
|
|
|
New Member ![]() Posts: 1 OS: windows XP |
Or maybe a PHP Templating System would do the trick, easily and instantly!
have you tried smarty? http://php.smarty.net |
|
|
Jun 30 2008, 06:21 PM
Post
#5
|
|
|
Member ![]() ![]() Posts: 88 From: Sydney, Australia OS: Windows XP |
I'm not too sure of how to explain these to you:
?page=content/page .. example index.php?page=guestbook But I will do my best. I know them as $_GET variables. To call this data you want to store use this code: $_GET['page'] $_GET is the method used, rather like $_POST in forms. To dynamically load pages which is what I think you want to do you want to store the $_GET['page'] in a variable like so: CODE $page = $_GET['page']; With that variable, which will have the value of whatever is set in the url, which we discussed in this example would be index.php?page=guestbook. So, the variable $page will have the value of guestbook Depending on the method you want to use to load the page (i recommend include) you will need to append a file extension to the variable. You can do this by either changing the variable $page from: CODE $page = $_GET['page']; to CODE $page = $_GET['page'] . ".php"; Or by adding a new line which will append the extension. Like so: CODE // Add this below the first $page variable $page .= ".php"; That will make the variable $page equal to $_GET['page'] with .php on the end of it So with our example, if we were to echo out $page.. It would look like CODE // echo $page; guestbook.php Now that you have the page you wanted to load stored in the variable $page, you can proceed to include that page in your website with the following code: CODE // Including a page include($page); Alternatively you could use require . Which is exactly the same as include except, as the name suggests, whatever is "required" MUST exist for the script to continue. if it doesn't, it will throw back a fatal error and code below the require code will not be executed. Creating hyperlinks to these pages is also simple. There is no special code, just put the URL in the hyperlink as you would expect it to look. Let's have a look at it with our guestbook example again. CODE // The hyperlink (in HTML) <a href="index.php?page=guestbook">Visit my guestbook! :)</a> And there you have it. Loading Mysql data with that variable can also be done. It looks a bit like this (you don't need to append the extension). // Creating the variable of the page name. CODE $page = $_GET['page']; // Creating the connection handler $connection = mysql_connect("host","username","pass"); // Selecting the database mysql_select_db("database_name",$connection) or die ("Could not select database"); // Creating the query, remember, double quotes are non-literal so you can include variables inside of them and they will work properly, unlike single quotes. $query = "SELECT content FROM pages WHERE page_name = $page"; // Storing the content inside the variable $content $content = mysql_query($query) or die (mysql_error()); // echo'ing out the content stored in $content echo $content; I hope that makes sense. It made sense my head atleast haha This post has been edited by Sp0nge: Jul 1 2008, 12:14 AM |
|
|
![]() ![]() |
Similar Topics
| Topic Title | Replies / Views | Topic Information | |||||
|---|---|---|---|---|---|---|---|
![]() |
4 / 404 | 17th August 2006 - 05:07 PM Rothers2005 started - last by Rothers2005 |
|||||
![]() |
1 / 1,668 | 26th August 2006 - 11:25 AM thenotch started - last by thenotch |
|||||
![]() |
0 / 260 | 7th March 2008 - 09:38 AM johnykit started - last by johnykit |
|||||
![]() |
3 / 411 | 30th June 2008 - 06:28 PM gmanpopinjay started - last by Sp0nge |
|||||
|
Time is now: 3rd December 2008 - 01:16 AM |
| Advertisements do not imply our endorsement of that product or service. The forum is run by volunteers who donate their time and expertise. We make every attempt to ensure that the help and advice posted is accurate and will not cause harm to your computer. However, we do not guarantee that they are accurate and they are to be used at your own risk. |