danhodge Posted January 9, 2011 Report Posted January 9, 2011 This should really contain a quick answer i guess, but i thought i would put it here for discussion... I am making a website which is going to be the homepage of what i do later on, including programs, templates and a portfolio. I'm doing the first draft, and i have 3 sidebars on the right, for which i used the <table> tags. Although this is a fairly easy way of doing this, its filling up my notepad page by way too much :S Is it possible for me to take out all of table HTML code, put it in a new HTML file, then link it into the original page, without it being a second page? Or do i just need to deal with this kind of issue? Thanks a lot, Danny Quote
danhodge Posted January 9, 2011 Author Report Posted January 9, 2011 Ahhh PHP So a PHP file can contain pure HTML code if needed? Quote
newseed Posted January 9, 2011 Report Posted January 9, 2011 The include file can be just about whatever you want it to contain. It's PHP that you use to process the include. Quote
danhodge Posted January 9, 2011 Author Report Posted January 9, 2011 Sorry, i made a stupid mistake here, i forgot some Javascript and no PHP work from Local host Infact, it still doesn't work, im trying PHP again :-/ <?php require($DOCUMENT_ROOT . "/public_html/table.html"); ?> I hate myself for googling code i don't understand Quote
falkencreative Posted January 9, 2011 Report Posted January 9, 2011 i forgot some Javascript and no PHP work from Local host You are running the code using a server of some sort, correct? You've installed something like WAMP or MAMP, and are accessing the PHP file through http://localhost/? (or, if you are testing your code on your hosting account, this should all be set up for you assuming your hosting supports PHP.) And the file that uses the <?php ?> code ends in .php? Assuming that is all true... You might want to check what value the $DOCUMENT_ROOT variable holds, just to make sure the path is correct. Instead of an include, try echoing (displaying) the path and make sure it is correct: <?php echo $DOCUMENT_ROOT . "/public_html/table.html"; ?> Quote
danhodge Posted January 10, 2011 Author Report Posted January 10, 2011 This is why i dont like PHP, i cant get my head around it :| I thought $DOCUMENT_ROOT could be anything, because it is being declared as $DOCUMENT_ROOT... Quote
falkencreative Posted January 10, 2011 Report Posted January 10, 2011 $DOCUMENT_ROOT is a constant that depends on your PHP setup. I want to make sure that the path to the include file that you are using is correct. For example, what if $DOCUMENT_ROOT includes "/public_html/", so your link actually looks like "your file path/public_html/public_html/table.html"? I imagine that wouldn't work. Also, another thing to note based on http://php.net/manual/en/language.variables.predefined.php - I'm pretty sure you need to be using "$_SERVER['DOCUMENT_ROOT']" rather than simply "$DOCUMENT_ROOT". Quote
danhodge Posted January 10, 2011 Author Report Posted January 10, 2011 So $_SERVER['DOCUMENT_ROOT'] needs renaming also, to link to the root of the files? And yeah, sorry, i guess i was reading a pretty outdated post on google... Quote
falkencreative Posted January 10, 2011 Report Posted January 10, 2011 No, $_SERVER['DOCUMENT_ROOT'] doesn't need renaming. If your includes are not working, I am suggesting that you display the paths in the page temporarily so you can check the paths to make sure they are accurate. Quote
danhodge Posted January 10, 2011 Author Report Posted January 10, 2011 Isn't this code more effort than it needs? Could i ask what code you would use to do a basic include of a part of a website? Im pretty certain i had all the paths correct, so i don't understand this at all :-/ Quote
falkencreative Posted January 10, 2011 Report Posted January 10, 2011 Could i ask what code you would use to do a basic include of a part of a website? You are using the correct code (assuming you are using $_SERVER['DOCUMENT_ROOT']) Can you just do what I have asked above? It's a 30 second change. This is the first step I would check, assuming you know that PHP is working. If PHP is working, then you have a path issue. Otherwise, I can't really help you and either you need to get help from someone else or drop the PHP includes idea. Quote
danhodge Posted January 10, 2011 Author Report Posted January 10, 2011 I think il just have to drop it, and il take PHP from the start again :L Sorry about that, hope i didn't waste too much of your time... Quote
falkencreative Posted January 10, 2011 Report Posted January 10, 2011 Well, definitely come back to it at a later point. PHP includes can be incredibly useful for reducing time spent on maintenance. Much easier to change one "footer.php" file rather than changing the code on 20 individual HTML files. Quote
danhodge Posted January 10, 2011 Author Report Posted January 10, 2011 Oh i will I know they are used for different things, but could PHP replace Javascript on your website with a bit of work? Quote
falkencreative Posted January 10, 2011 Report Posted January 10, 2011 I know they are used for different things, but could PHP replace Javascript on your website with a bit of work? Not really. While PHP can do some of the things that Javascript can, they are not interchangeable. To borrow from http://answers.yahoo.com/question/index?qid=20080102151225AAlMHOC The two are intended to control different things and work in completely different environments with different runtime models. PHP is primarily server-side, back-end language that is used to produce web pages. PHP is interpreted by a module built into web server. The primary purpose of a PHP program is to produce text output that will become web page and perform actions such as database updates in response to input submitted from web browsers. Javascript is a language that is understood by web browsers. In a nutshell, it just tells browser how to alter the web page look and behavior once it has already been rendered in the browser window. Javascript is intepreted by the browser only and usually has no direct communication with web server. Javascript operates with HTML objects like buttons, DIV elements, input text fields, images, CSS styles and so on. Quote
danhodge Posted January 10, 2011 Author Report Posted January 10, 2011 Ahh okay then Well, i think learning Javascript is still gonna be my priority - its much simpler than PHP, and more useful for what i currently need on my project Thanks so much for all this, i only started HTML coding about a month or 2 ago, PHP is a lot to get my head around sometimes... Quote
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.
Note: Your post will require moderator approval before it will be visible.