Jump to content

[SOLVED] Strange issue echoing template?


Solarpitch

Recommended Posts

Hey,

 

I currently have a template class set up called page_1.php and I have created a new instance of it below. The problem I'm having is when I make a call to the get_content() function to diaply the content on the page, it display's the content before the template so everything prints to screen before the start of the document.

 

index.php....

 

<?php

require ("page_1.php");
require 'dbparams/dbparams.php';

$id= 1;

$home = new page();

$home ->content = "

<div id='content'>

        ".get_content($id)."

        </div>

        ";

        $home ->Display();

?>

 

page_1.php...

 

<?php

//this is the display function in the class that prints the webpage...

public function Display()
{

	echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';

	echo "<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n<head>\n";

	$this -> DisplayMeta();
	$this -> DisplayScripts();
	$this -> DisplayStyles();

	echo "</head>\n<body onload=\"new Accordian('basic-accordian',5,'header_highlight');\">";

	$this -> DisplayHeader();
	$this -> DisplayLeftNav();

	echo $this->content;

	$this -> DisplayFooter();

	echo "</body>\n</html>";

}


?>

 

 

So the content will print like...

 


This is the content for the page... this prints before the document like so..

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
<head>..... etc



 

 

Link to comment
https://forums.phpfreaks.com/topic/129465-solved-strange-issue-echoing-template/
Share on other sites

Hey,

 

here is the get_content() function I have... is this wrong?

 

<?php

function get_content($id)
{

dbconnect();

    $sql = "SELECT * FROM pvr_content where id = ".$id." ORDER BY id asc";
$result = mysql_query($sql);

        while(($row = mysql_fetch_row($result)) != false) 
		{

	     echo "	
  <p>".$row[1]."</p>
";


    }

}

?>

yeah, it needs to return a string...like so:

 

<?php

function get_content($id)
{
   dbconnect();
   $sql = "SELECT * FROM pvr_content where id = ".$id." ORDER BY id asc";
   $result = mysql_query($sql);
   
   $contents = "";
   while(($row = mysql_fetch_row($result)) != false) 
   {
      $contents .= "\n<p>".$row[1]."</p>\n";
   }
   return $contents;
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.