Jump to content

include() issues...


MinusMyThoughts
 Share

Recommended Posts

hey, guys!...so i've wrestled my current project to within inches of completion, and now i've got a small-but-annoying problem that i can't seem to figure out......my site is formatted from an included file called "siteLook.php" that contains all of the tables and images and divs and so on. within my "siteLook.php" file, there is a call to include a file called "eventBox.php" that holds an event calendar and all the code to run it......all of it works, but it's loading in a rather unsavory way: the data for "eventBox.php" loads first, displaying on the screen for a second or two before giving way to the properly formatted page......the call to the $eventBox variable (this calls to "siteLook.php" and activates the include() function for "eventBox.php") is the last thing in the script aside from the closing HTML tags for the page......i'm not sure how to combat this problem, so if anyone knows where i could find a resource that would help me out or has had this problem and knows a fix, i'd be extremely grateful......also, i didn't want to post my code because i wasn't sure which bits would be useful in seeing where the problem lies, and posting all three files seemed cumbersome...love,jason

Link to comment
Share on other sites

THIS is the beta site i'm working on. the glitch is across the board, so any link should cause the problem......i've tried both FF and IE, both causing a variation of the same problem......thanks!love,jason
Link to comment
Share on other sites

Load your page and view the HTML source. The very first thing on the page is a <div> tag. It looks like you are including the file first thing, and it gets outputted right away, before the <html> and <body> tags. If the include file contains a lot of HTML in it, then you will need to include it at the point where you want the HTML. So, after you send the <html> and <head> and all that stuff, get down to where you want the div to appear and then do the include at that point.

Link to comment
Share on other sites

-->index.php (This is the displayed file)

<?php  require 'update/aKa_db-connect.php';  $query = 'SELECT * FROM aKa_content WHERE contentID=1';  $result = mysql_query($query);  $text = mysql_fetch_array($result);  $contentText = $text['contentText'];  $pageName = 'home';  include('aKa_siteLook.php');  echo $siteLook;  echo '<p class="content">'	. $contentText	. '</p>';  echo $siteFoot;  echo $emailBox;  echo $eventBox;  echo '</body></html>';?>

-->aKa_siteLook.php ($eventBox calls the include())

<?php  $siteLook = '<html><head>'	. '<title>American Karate Academy - Whitefish, MT</title>'	. '<link rel="stylesheet" href="aKa.css" type="text/css" media="screen,projection" />'	.'<link rel="SHORTCUT ICON" href="favicon.ico">'	. '</head>'	. '<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">'	. '<table width="801" height="656" border="0" cellpadding="0" cellspacing="0">'	. '<tr>'	. '<td rowspan="2" align="left" valign="top" '	. 'background="images/aKa_siteLook_01.gif" width="224" height="206" alt=""></td>'	. '<td align="left" valign="top" background="images/aKa_' 	. $pageName 	. '_02.gif" width="350" height="133" alt=""></td>'	. '<td rowspan="10" align="left" valign="top" '	. 'background="images/aKa_siteLook_03.gif" width="226" height="655" alt=""></td>'	. '<td background="images/spacer.gif" width="1" height="133" alt=""></td>'	. '</tr><tr>'	. '<td rowspan="9" align="left" valign="top" '	. 'background="images/aKa_siteLook_05.gif" width="350" height="522" alt=""></td>'	. '<td background="images/spacer.gif" width="1" height="73" alt=""></td>'	. '</tr><tr><td align="left" valign="top">'	. '<a href="index.php"><img src="images/aKa_' 	. $pageName 	. '_06.gif" width="224" height="30" border="0"></a></td>'	. '<td background="images/spacer.gif" width="1" height="30" alt=""></td>'	. '</tr><tr><td align="left" valign="top">'	. '<a href="about.php"><img src="images/aKa_' 	. $pageName 	. '_07.gif" width="224" height="27" border="0"></a></td>'	. '<td background="images/spacer.gif" width="1" height="27" alt=""></td>'	. '</tr><tr><td align="left" valign="top">'	. '<a href="schedule.php"><img src="images/aKa_' 	. $pageName 	. '_08.gif" width="224" height="27" border="0"></a></td>'	. '<td background="images/spacer.gif" width="1" height="27" alt=""></td>'	. '</tr><tr><td align="left" valign="top">'	. '<a href="pictures.php"><img src="images/aKa_' 	. $pageName 	. '_09.gif" width="224" height="29" border="0"></a></td>'	. '<td background="images/spacer.gif" width="1" height="29" alt=""></td>'	. '</tr><tr><td align="left" valign="top">'	. '<a href="contact.php"><img src="images/aKa_' 	. $pageName 	. '_10.gif" width="224" height="27" border="0"></a></td>'	. '<td background="images/spacer.gif" width="1" height="27" alt=""></td>'	. '</tr><tr><td align="left" valign="top">'	. '<a href="praise.php"><img src="images/aKa_' 	. $pageName 	. '_11.gif" width="224" height="28" border="0"></a></td>'	. '<td background="images/spacer.gif" width="1" height="28" alt=""></td>'	. '</tr><tr><td align="left" valign="top">'	. '<a href="FAQ.php"><img src="images/aKa_' 	. $pageName 	. '_12.gif" width="224" height="26" border="0"></a></td>'	. '<td background="images/spacer.gif" width="1" height="26" alt=""></td>'	. '</tr><tr>'	. '<td rowspan="2" align="left" valign="top" '	. 'background="images/aKa_siteLook_13.gif" width="224" height="256" alt=""></td>'	. '<td background="images/spacer.gif" width="1" height="255" alt=""></td>'	. '</tr><tr>'	. '<td colspan="2" background="images/aKa_siteLook_14.gif" '	. 'width="576" height="1" alt=""></td>'	. '<td background="images/spacer.gif" width="1" height="1" alt=""></td>'	. '</tr></table><div class="contentColor"></div><div class="content">';  $siteUpdate = '<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">'	. '<table width="801" height="656" border="0" cellpadding="0" cellspacing="0">'	. '<tr>'	. '<td rowspan="2" align="left" valign="top" '	. 'background="images/aKa_siteLook_01.gif" width="224" height="206" alt=""></td>'	. '<td align="left" valign="top" background="images/aKa_' 	. $pageName 	. '_02.gif" width="350" height="133" alt=""></td>'	. '<td rowspan="10" align="left" valign="top" '	. 'background="images/aKa_siteLook_03.gif" width="226" height="655" alt=""></td>'	. '<td background="images/spacer.gif" width="1" height="133" alt=""></td>'	. '</tr><tr>'	. '<td rowspan="9" align="left" valign="top" '	. 'background="images/aKa_siteLook_05.gif" width="350" height="522" alt=""></td>'	. '<td background="images/spacer.gif" width="1" height="73" alt=""></td>'	. '</tr><tr><td align="left" valign="top">'	. '<a href="index.php"><img src="images/aKa_' 	. $pageName 	. '_06.gif" width="224" height="30" border="0"></a></td>'	. '<td background="images/spacer.gif" width="1" height="30" alt=""></td>'	. '</tr><tr><td align="left" valign="top">'	. '<a href="about.php"><img src="images/aKa_' 	. $pageName 	. '_07.gif" width="224" height="27" border="0"></a></td>'	. '<td background="images/spacer.gif" width="1" height="27" alt=""></td>'	. '</tr><tr><td align="left" valign="top">'	. '<a href="schedule.php"><img src="images/aKa_' 	. $pageName 	. '_08.gif" width="224" height="27" border="0"></a></td>'	. '<td background="images/spacer.gif" width="1" height="27" alt=""></td>'	. '</tr><tr><td align="left" valign="top">'	. '<a href="pictures.php"><img src="images/aKa_' 	. $pageName 	. '_09.gif" width="224" height="29" border="0"></a></td>'	. '<td background="images/spacer.gif" width="1" height="29" alt=""></td>'	. '</tr><tr><td align="left" valign="top">'	. '<a href="contact.php"><img src="images/aKa_' 	. $pageName 	. '_10.gif" width="224" height="27" border="0"></a></td>'	. '<td background="images/spacer.gif" width="1" height="27" alt=""></td>'	. '</tr><tr><td align="left" valign="top">'	. '<a href="praise.php"><img src="images/aKa_' 	. $pageName 	. '_11.gif" width="224" height="28" border="0"></a></td>'	. '<td background="images/spacer.gif" width="1" height="28" alt=""></td>'	. '</tr><tr><td align="left" valign="top">'	. '<a href="FAQ.php"><img src="images/aKa_' 	. $pageName 	. '_12.gif" width="224" height="26" border="0"></a></td>'	. '<td background="images/spacer.gif" width="1" height="26" alt=""></td>'	. '</tr><tr>'	. '<td rowspan="2" align="left" valign="top" '	. 'background="images/aKa_siteLook_13.gif" width="224" height="256" alt=""></td>'	. '<td background="images/spacer.gif" width="1" height="255" alt=""></td>'	. '</tr><tr>'	. '<td colspan="2" background="images/aKa_siteLook_14.gif" '	. 'width="576" height="1" alt=""></td>'	. '<td background="images/spacer.gif" width="1" height="1" alt=""></td>'	. '</tr></table>';  $emailBox = '<div class="email"><h3 class="email">'	. 'Join Our Newsletter!'	. '</h3><p class="email">'	. 'Keep up to date with<br/>'	. 'American Karate Academy<br/>'	. 'news and events with our<br/>'	. 'FREE Newsletter!'	. '</p>'	. '<form action="aKa_emailList.php" method="post">'	. '<input type="text" class="w100">'	. '<input type="submit" value="Join!" class="w50"></div>'	. '<div class="emailColor"><h3 class="email">'	. 'Join Our Newsletter!'	. '</h3><p class="email">'	. 'Keep up to date with<br/>'	. 'American Karate Academy<br/>'	. 'news and events with our<br/>'	. 'FREE Newsletter!'	. '</p>'	. '<form action="aKa_emailList.php" method="post">'	. '<input type="text" name="emailList" class="w100">'	. '<input type="submit" value="Join!" class="w50"></div>';  $eventBox = include('eventBox.php');  $siteFoot = '</div>';?>

NOTE: i can't see how anything but the "$eventBox = include('eventBox.php');" would affect anything about the load order, but that shows you how the HTML should be printed as i call it in "index.php"...-->eventBox.php (this runs a handful of functions and prints out my formatted eventBox <div>)

<?php  $currentTime = time() - 3 * 60 * 60;  $query = mysql_query('SELECT * FROM aKa_event WHERE eventTimestamp>="'	.$currentTime	.'" ORDER BY eventTimestamp ASC LIMIT 3');  echo '<div class="event"><h3 class="email">'	. 'Upcoming Events:'	. '</h3>';  while($display = mysql_fetch_array($query))  {	$AMPM = 'AM';	if($display['eventAMPM'] == 12)	  {	  $AMPM = 'PM';	  }  switch($display['eventMonth'])	{	case '1':	  $monthName = '01';	  break;	case '2':	  $monthName = '02';	  break;	case '3':	  $monthName = '03';	  break;	case '4':	  $monthName = '04';	  break;	case '5':	  $monthName = '05';	  break;	case '6':	  $monthName = '06';	  break;	case '7':	  $monthName = '07';	  break;	case '8':	  $monthName = '08';	  break;	case '9':	  $monthName = '09';	  break;	case '10':	  $monthName = '10';	  break;	case '11':	  $monthName = '11';	  break;	case '12':	  $monthName = '12';	  break;	default:	case '':	  $monthName = 'ERROR!';	  break;	}  switch($display['eventYear'])	{	case '2006':	  $yearName = '06';	  break;	case '2007':	  $yearName = '07';	  break;	case '2008':	  $yearName = '08';	  break;	default:	case '':	  $yearName = 'ERROR!';	  break;	}  switch($display['eventDay'])	{	case '1':	  $dayName = '01';	  break;	case '2':	  $dayName = '02';	  break;	case '3':	  $dayName = '03';	  break;	case '4':	  $dayName = '04';	  break;	case '5':	  $dayName = '05';	  break;	case '6':	  $dayName = '06';	  break;	case '7':	  $dayName = '07';	  break;	case '8':	  $dayName = '08';	  break;	case '9':	  $dayName = '09';	  break;	case '10':	  $dayName = '10';	  break;	case '11':	  $dayName = '11';	  break;	case '12':	  $dayName = '12';	  break;	case '13':	  $dayName = '13';	  break;	case '14':	  $dayName = '14';	  break;	case '15':	  $dayName = '15';	  break;	case '16':	  $dayName = '16';	  break;	case '17':	  $dayName = '17';	  break;	case '18':	  $dayName = '18';	  break;	case '19':	  $dayName = '19';	  break;	case '20':	  $dayName = '20';	  break;	case '21':	  $dayName = '21';	  break;	case '22':	  $dayName = '22';	  break;	case '23':	  $dayName = '23';	  break;	case '24':	  $dayName = '24';	  break;	case '25':	  $dayName = '25';	  break;	case '26':	  $dayName = '26';	  break;	case '27':	  $dayName = '27';	  break;	case '28':	  $dayName = '28';	  break;	case '29':	  $dayName = '29';	  break;	case '30':	  $dayName = '30';	  break;	case '31':	  $dayName = '31';	  break;	default:	case '':	  $dayName = 'ERROR!';	  break;	}  $description = explode(' ', $display['eventDescription']);  $i = 0;  echo '<p class="event">'	. '<table width="100%" border="0" cellpadding="0" '	. 'cellspacing="0"><tr><td align="left">'	. '<p class="eventTitle"><b>'	.$monthName	.'/'	.$dayName	.'/'	.$yearName	.' | '	. $display['eventTitle']	.'</b></p></td><td align="right">'	. '</td></tr><tr><td>'	. '<p class="eventDescription">';  while ($i <= 9)	  {		echo stripslashes($description[$i]) . ' ';		$i++;	  }  echo '...</p>'	. '</td></tr><tr><td colspan="2" align="right">'	. '<a href="event.php?eventID='	. $display['eventID']	. '" class="eventLink">(view)</a>'	. '<hr color="FFFFFF" width="95%" style="margin-top:0px; '	. 'margin-bottom:0px"></td></tr></table>';  }  echo '<table width="100%" border="0" cellpadding="0" '	. 'cellspacing="0">'	. '<tr><td align="right">'	. '<a href="event.php?eventID=all" class="eventLink">(view all)</a>'	. '</td></tr></table></div>';  $query = mysql_query('SELECT * FROM aKa_event WHERE eventTimestamp>="'	.$currentTime	.'" ORDER BY eventTimestamp ASC LIMIT 3');  echo '<div class="eventColor"><h3 class="email">'	. 'Upcoming Events:'	. '</h3>';  while($display = mysql_fetch_array($query))  {	$AMPM = 'AM';	if($display['eventAMPM'] == 12)	  {	  $AMPM = 'PM';	  }  switch($display['eventMonth'])	{	case '1':	  $monthName = '01';	  break;	case '2':	  $monthName = '02';	  break;	case '3':	  $monthName = '03';	  break;	case '4':	  $monthName = '04';	  break;	case '5':	  $monthName = '05';	  break;	case '6':	  $monthName = '06';	  break;	case '7':	  $monthName = '07';	  break;	case '8':	  $monthName = '08';	  break;	case '9':	  $monthName = '09';	  break;	case '10':	  $monthName = '10';	  break;	case '11':	  $monthName = '11';	  break;	case '12':	  $monthName = '12';	  break;	default:	case '':	  $monthName = 'ERROR!';	  break;	}  switch($display['eventYear'])	{	case '2006':	  $yearName = '06';	  break;	case '2007':	  $yearName = '07';	  break;	case '2008':	  $yearName = '08';	  break;	default:	case '':	  $yearName = 'ERROR!';	  break;	}  switch($display['eventDay'])	{	case '1':	  $dayName = '01';	  break;	case '2':	  $dayName = '02';	  break;	case '3':	  $dayName = '03';	  break;	case '4':	  $dayName = '04';	  break;	case '5':	  $dayName = '05';	  break;	case '6':	  $dayName = '06';	  break;	case '7':	  $dayName = '07';	  break;	case '8':	  $dayName = '08';	  break;	case '9':	  $dayName = '09';	  break;	case '10':	  $dayName = '10';	  break;	case '11':	  $dayName = '11';	  break;	case '12':	  $dayName = '12';	  break;	case '13':	  $dayName = '13';	  break;	case '14':	  $dayName = '14';	  break;	case '15':	  $dayName = '15';	  break;	case '16':	  $dayName = '16';	  break;	case '17':	  $dayName = '17';	  break;	case '18':	  $dayName = '18';	  break;	case '19':	  $dayName = '19';	  break;	case '20':	  $dayName = '20';	  break;	case '21':	  $dayName = '21';	  break;	case '22':	  $dayName = '22';	  break;	case '23':	  $dayName = '23';	  break;	case '24':	  $dayName = '24';	  break;	case '25':	  $dayName = '25';	  break;	case '26':	  $dayName = '26';	  break;	case '27':	  $dayName = '27';	  break;	case '28':	  $dayName = '28';	  break;	case '29':	  $dayName = '29';	  break;	case '30':	  $dayName = '30';	  break;	case '31':	  $dayName = '31';	  break;	default:	case '':	  $dayName = 'ERROR!';	  break;	}  $description = explode(' ', $display['eventDescription']);  $i = 0;  echo '<p class="event">'	. '<table width="100%" border="0" cellpadding="0" '	. 'cellspacing="0"><tr><td align="left">'	. '<p class="eventTitle"><b>'	.$monthName	.'/'	.$dayName	.'/'	.$yearName	.' | '	. $display['eventTitle']	.'</b></p></td><td align="right">'	. '</td></tr><tr><td>'	. '<p class="eventDescription">';  while ($i <= 9)	  {		echo stripslashes($description[$i]) . ' ';		$i++;	  }  echo '...</p>'	. '</td></tr><tr><td colspan="2" align="right">'	. '<a href="event.php?eventID='	. $display['eventID']	. '" class="eventLink">(view)</a>'	. '<hr color="FFFFFF" width="95%" style="margin-top:0px; '	. 'margin-bottom:0px"></td></tr></table>';  }  echo '<table width="100%" border="0" cellpadding="0" '	. 'cellspacing="0">'	. '<tr><td align="right">'	. '<a href="event.php?eventID=all" class="eventLink">(view all)</a>'	. '</td></tr></table></div>';?>

NOTE: the code repeats itself to clear up an opacity issue i had. in order to get a transparency on the background and opaque text, my solution was to run the div once with the alpha set at 60% and the background color set, then run a transparent background 100% alpha <div> with the same text. sloppy? probably......sorry about all the code. i was hesitant to post it because i knew it would be ridiculously long......if my understanding of the way it should be reading my scripts is correct, then the include() shouldn't run until it's called in the variable. however, i think when "aKa_siteLook.php" is required, the include() runs regardless. my update page is displaying an eventBox that isn't called now......i've tried defining a function and calling it from the variable like so:

function eventBox()  {  include('eventBox.php');  }$eventBox = eventBox();

but that had the same glitch......i tried calling that function from the display page itself, which i see as possibly the most logical way to avoid this problem, but that left me with an error reading "call to an undefined function 'eventBox()'" which leads me to believe that i needed an extra step to make a function from an included file hold valid in the file that called it......anyways. if you guys know something that might help, i'm ALL ears...love,jason

Link to comment
Share on other sites

The reason is because of all of the echo statements in the eventBox.php file. When the file gets included, it immediately prints everything. You can use return statements in an include file if you want. So, instead of echo statements, you can build a return value and then return it at the end.eventBox.php:

<?php$retval = "";$retval .= "<div ...";// all your code, adding to $retval instead of echoingreturn $retval;?>

And then when you do $eventBox = include ("eventBox.php"), instead of having everything immediately print in the include file, it will store everything in the $retval variable inside eventBox.php, and then save that into the $eventBox variable so that you can print it later when you want.Or, you can just remove the call to include eventBox.php in the siteLook.php file, and instead of echoing the $eventBox variable in your main file, just call include("eventBox.php") at that point. Then, it will include the file and print everything out with the echo statements.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...