Forum Moderators: coopster

Message Too Old, No Replies

include help

php include

         

meanweaver

12:12 am on Mar 9, 2004 (gmt 0)

10+ Year Member



I have been playing with php includes and thought it would be interesting to create a table say 3 rows 3 cols and put an include in each table cell pointing to other sites, i thought make each cell 500px wide and i would have a page with say four news sites from different countries, so i built my table added this in
<?php include("http://www.cnn.com")?>

plus others uploaded it then sat back to watch my master peice in action, but hey guess what! includes dont quite work like that, the sites all loaded under each other and the page was veery wide, and even my nav table include had the same rollover effect as the first site in the includes.
Is there a way this can be done easily or should i forget this idea now, I have no need for this on my site I am just at the start of learning php so have tried this just for education reasons.

Regards Ian

jatar_k

12:27 am on Mar 9, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



meanweaver, I love how you write.

uploaded it then sat back to watch my master peice in action

rofl, I have done the same so many times with roughly the same results, though I have brought down a few servers too. ;)

no, includes don't really work like that. You included the whole html page from each site and therefore literally blew yours to shreds.

You can't really include full pages like that. Think about the html structure. You would have referenced 5 css files, 5 js files, have 5 html, head, title and body tags among various other problems. View the source on that page, it would give you an idea of the actual html chaos that ensued.

What you would want to include is a piece of the page, not the whole thing. If you wanted news you could look at RSS feeds where the stories are sent out stripped (very loose description) and can be formatted to be used on your site.

The include function, literally, just grabs the output of the targetted file and dumps it into your page wherever the include statement is.

meanweaver

12:58 am on Mar 9, 2004 (gmt 0)

10+ Year Member



Thanks for the reply, well i see what you mean about the html code, now you mention it and i have thought about what i am doing i can see why now, When you refer to the rss, I am not quite sure what this refers to, I have for once given this some thought but i cant see how i refer to just part of another sites html page, I also have some questions on the best scripts for a contact form but i think i should start another thread for that, or maybe wait for my php for dummies book to arrive.

Regards Ian

mykel79

7:40 pm on Mar 9, 2004 (gmt 0)

10+ Year Member



Includes are meant to be used for a different purpose. Say you have a piece of code that is the same in each php script you have, then you can put in in a seperate php file and include it in every script (instead of writing it over and over in every php you have on a site). When you need to make a change to that common piece of code, you just change it in one file.

As for what you were trying to do, that can be done by using frames or iframes -but no need for includes.