Solarpitch Posted October 21, 2008 Share Posted October 21, 2008 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 More sharing options...
rhodesa Posted October 21, 2008 Share Posted October 21, 2008 does get_content() PRINT or RETURN the contents? make sure the function is returning a string with the content in it, and not doing echo/print Link to comment https://forums.phpfreaks.com/topic/129465-solved-strange-issue-echoing-template/#findComment-671178 Share on other sites More sharing options...
Solarpitch Posted October 21, 2008 Author Share Posted October 21, 2008 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> "; } } ?> Link to comment https://forums.phpfreaks.com/topic/129465-solved-strange-issue-echoing-template/#findComment-671185 Share on other sites More sharing options...
rhodesa Posted October 21, 2008 Share Posted October 21, 2008 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; } ?> Link to comment https://forums.phpfreaks.com/topic/129465-solved-strange-issue-echoing-template/#findComment-671187 Share on other sites More sharing options...
Solarpitch Posted October 21, 2008 Author Share Posted October 21, 2008 Perfect. That had me for the last few hours. Thanks, Ger. Link to comment https://forums.phpfreaks.com/topic/129465-solved-strange-issue-echoing-template/#findComment-671191 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.