Jump to content

[SOLVED] dependent includes?


el_bob

Recommended Posts

hi -

 

i've got a page someone else built with an include for another file. the include needed a random banner, both jpeg and swf.

 

so i figured that one out - i've set up an include in that file which calls the proper code randomly from a text file, one line with the embed for the swf and one line with the image (both in their own link tag - a href...)

 

so here's the issue -

 

back on the top level, there's another banner which needs to be dependent on the include inside the include.  they're in 2 completely different places, so tying them into the same file is not an option.

 

i have ABSOLUTELY no idea where to even start on that one.

 

anyone??

Link to comment
Share on other sites

do you mean something like this?

 

<?PHP
//code before the head of the html
?>
HTML HEAD STUFF
<body>
<?PHP
//php code
include 'xxx.xxx';
//more code
include 'xxx.xxx';
//more code...
?>
</body>
END OF THE FILE

 

if not then can you try and explain more clearly

Link to comment
Share on other sites

sorry - i'll try to explain better

 

here's the page hierarchy

 

  • regular page
       

    •        
  • header include.php
           

    •            
  • banner randomizer include.php (getting html source code from text file)
               

       

   

   

[*]more regular page stuff

[*]other regular page banner which needs to be dependent on banner randomizer include.php result

 

 

make more sense?

 

Link to comment
Share on other sites

not preticullary, im still stuck with what your saying,

 

you mean a structure like this?

 

index.php (for instance)

|-include 'zzzz.php'

||-include 'yyyy.php'

|-include 'xxxx.php'

||-include 'wwww.php'

 

so you include 2 files, and both those files include more files?

 

i really dont get what you mean, can you post the code?

Link to comment
Share on other sites

sorry, i can't.

 

but

 

index.php

|-include 'header.php'

||-include 'get_banner.php'

|||random.txt (contains html to be placed into index.php, seperated by carriage returns)

content

skyscraper dependent on results of index/header/get_banner  (THIS IS THE ONE I NEED)

 

 

 

so i include one file, which includes another file, which feeds info into the index from yet another file.

 

Link to comment
Share on other sites

ok, all you need in the index.php file is:

include 'xxxx.php'

inside that you need:

include 'xxxx.php'

then add this inside that:

include 'xxxx.txt'

 

so then the index file will show the txt file along with the other files

 

Index.php:

include 'header.php';

header.php

include 'get_banner.php';

get_banner.php

include 'random.txt';

Link to comment
Share on other sites

right - i've already got that

 

but let's say "random.txt" put the following line of code into index.php -

 

<a href="http://www.joeschmoe.com" target"_blank"><img src="banners/joeschmoebanner.jpg" /></a>

 

how do i then make sure that the next banner down gets the message that this is a joeschmoe page and not a fredschmed page, and loads a joeschmoe image accordingly?

 

to cut off a few simple ideas already passed:

 

can't have different pages - bookmark needs to always go back to index.

can't setup a "joeschmoe" tag, cuz the doubly-nested "get_banner.php" won't get the message

Link to comment
Share on other sites

ok, i think i fixeded it....

 

in the .txt file, i added an element id (same - banner) and a class (different - numbered 1-whatever for ease)

 

in the index doc, i added a javascript to get the class of banner and write html code base on that

 

NOW

 

since my php is limited to looking at an existing script and twiddling with it once i see what links with what

 

is there code to do this in php?

 

here's the javascript

 

<script language="JavaScript" type="text/javascript">
  var el_banner = document.getElementById("banner");
  	if (el_banner.className=="1") {
	document.write ('<a href="http:\/\/www.joeschmoe.com" target="_blank"><img src="Banners\/joeschmoeTall.jpg" width="160" height="600"><\/a> ');
} else {
	document.write ('<a href="http:\/\/www.fredschmed.com" target="_blank"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=7,0,19,0" width="160" height="600" title="fredschmed">')
        document.write ('<param name="movie" value="Banners\/fredschmedTall.swf">')
        document.write ('<param name="quality" value="high">')
        document.write ('<embed src="Banners\/fredschmedtall.swf" quality="high" pluginspage="http:\/\/www.macromedia.com\/go\/getflashplayer" type="application\/x-shockwave-flash" width="160" height="600"><\/embed>')
        document.write ('<\/object><\/a>');
	}
</script>

Link to comment
Share on other sites

try this:

 

$chars = array('<a href="http://www.joeschmoe.com" target="_blank"><img src="Banners/joeschmoeTall.jpg" width="160" height="600"></a>', <a href="http:\/\/www.fredschmed.com" target="_blank"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=7,0,19,0" width="160" height="600" title="fredschmed">');
$length = 1;
$textstr = "";
for ($i=0; $i<$length; $i++) {
   $textstr .= $chars[rand(0, count($chars)-1)];
}

echo $textstr;

Link to comment
Share on other sites

maybe i'm wrong, but you're giving me a script which puts in a random image, right?

 

i've already decided up at the header what the random is, now i want to take that random decision and apply it to the side.

Link to comment
Share on other sites

ok, if you are using that code i just gave you, then just change it to:

 

$chars = array('<a href="http://www.joeschmoe.com" target="_blank"><img src="Banners/joeschmoeTall.jpg" width="160" height="600"></a>', <a href="http:\/\/www.fredschmed.com" target="_blank"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=7,0,19,0" width="160" height="600" title="fredschmed">');
$length = 1;
$textstr = "";
for ($i=0; $i<$length; $i++) {
   $textstr .= $chars[rand(0, count($chars)-1)];
}

 

and then place this whereever you want it:

 

echo $textstr;

 

if its not that then just tell me

Link to comment
Share on other sites

nope, fixed it

 

so i just added the skyscraper code to the txt file using a --/-- delimiter, got the whole line using the carriage return delimiter, exploded the pieces using the --/-- and printed the pieces where i needed them.

 

so the code is

 

$filename = "random.txt";
$file = file($filename);

  srand((double)microtime()*1000000);
  while ($RandomRotator == "") {
  $RandomRotator = ereg_replace("\n","",$file[rand(0,count($file))]);
  }

$pieces = explode("--/--", $RandomRotator);
print $pieces[0];

 

and then later in the page

 

print $pieces[1];

Link to comment
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.