Forum Moderators: coopster

Message Too Old, No Replies

some info needed about include()

an include between a div id

         

ankurbajaj 9

10:13 pm on Dec 23, 2008 (gmt 0)

10+ Year Member



well i have a simple query

if i have a code like this
<div>
<?php include("some file")?>
</div>

<p>
hello
</p>
<div>
<?php include("some file 2")?>
</div>

what will happen

the two includes files will be included in the file and the data of file 1 and file 2 will be added to the php file in random?

the data of file 1 will be between the first div then hello then data of div 2?

coopster

10:28 pm on Dec 23, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, ankurbajaj 9.

It will happen in "top down" sequence, or procedural sequence as we often say. So, say you had a global variable defined in "some file" named $myVarFromSomeFile, you could actually refer to that variable in "some file 2" if necessary. It's a terrible example as that is really not an ideal programming practice, but a good example to explain how the included files get loaded and how the scope of your variables would be available.

ankurbajaj 9

10:38 pm on Dec 23, 2008 (gmt 0)

10+ Year Member



so the second option will happen

thanks for such a quick reply

coopster

10:45 pm on Dec 23, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yes, and you are welcome. I didn't realize you were posing a question there, but I see it now. Give it a test, add a PHP exit [php.net] in there ...
<div><?php include "some file"; ?></div> 
<p>hello</p>
<?php exit; ?>
<div><?php include "some file 2"; ?></div>

See how your included file showed up? View Source in your browser if you cannot tell, the PHP code should be rendered there. Nothing shows up after the exit statement. No randomness about it, it is procedural :)

A helpful link ... Basic syntax [php.net]

ankurbajaj 9

11:02 pm on Dec 23, 2008 (gmt 0)

10+ Year Member



doesnt seem to work

i made this site long ago

i tried using this technique but it didnt work correctly when u open the site and view the source code
u will see a div with class whit
empty
which in reality contains all the data that is below the div
tell me if u need any other info to understand the problem

<body class="whole">
<?php require("top.php");?>

<?php require("pulldown.php");?>

<?php require("home.php"); ?>
</body>

actually this is the index file
and whit is in home.php

[edited by: coopster at 12:34 pm (utc) on Dec. 24, 2008]
[edit reason] no personal urls please TOS [webmasterworld.com] [/edit]

coopster

12:38 pm on Dec 24, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The code was there when I looked so I assume you got it figured out. The best way to troubleshoot any included file issues is to first check your error logs.

ankurbajaj 9

12:58 pm on Dec 24, 2008 (gmt 0)

10+ Year Member



i faced this problem months ago and today i need to work on included files again

and
the problem is still not solved

can u open the site and see the code please?

coopster

1:14 pm on Dec 24, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I did. It showed a <table> element with a marquee in it.

ankurbajaj 9

1:24 pm on Dec 24, 2008 (gmt 0)

10+ Year Member



the div with class whit is showing empty which is not wat i planned

coopster

1:27 pm on Dec 24, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



It's not empty for me, there is a table with a marquee element inside. I am using Firefox as my web browser. If you are using a different browser perhaps you have a caching issue. Clear the browser cache and load the page again. Also, if you have any JavaScript or IE conditional comments, be certain they are not failing.

ankurbajaj 9

1:54 pm on Dec 24, 2008 (gmt 0)

10+ Year Member



actually i was using firebug

in that it was showing that way

thanks my doubt has been cleared