Forum Moderators: coopster
I am having problems using the echo statement inside a function. Here are the details:
I have the following function under a file named "functions.php":
function retrieveComments() //function to retrieve user comments
{
$i = 0;
$value ='';
$page = (is_numeric($_GET['page'])) ? $_GET['page'] : 1; //used for pagination
$limit = 15;
$from = ($limit * $page) - $limit;$dbConn = new dbConnection();
//connect
$dbConn->connect();
$sql="SELECT username,comments,timeStamp,id FROM comments ORDER BY id DESC LIMIT $from, $limit";
$result=mysql_query($sql) or die(mysql_error());
//calculate total pages
$total_entries = mysql_num_rows(mysql_query("SELECT * FROM comments"));
$total_pages = ceil($total_entries / $limit);
//temporarily put data into array and keep printing it out until there is no more
while($info=mysql_fetch_array($result))
{
$comment = $info['comments'];
$username = $info['username'];
$timeStamp = $info['timeStamp'];
$postID = $info['id'];
$lettermyusername = substr($username, 0,1);
$replies = $dbConn->userReplyCount($postID);
$counter = $i;
$myProfilePic2 = "<img src='/users/".$lettermyusername."/".$username."/".$username.".ProfilePic.".$dbConn->getUserPicExtension($username)."' height=100 width=100 alt='User picture'/>";
$this->value .=' //put everything inside "value" variable
<table id="userPost">
<tr><td id="activeUserPic">'.$myProfilePic2.'</td><td>Space</td><td valign="top" width=500px colspan=2><a href="commentPageTemplate.php?username='.$username.'&postID='.$postID.'&userPic='.$myProfilePic2.'&counter='.$counter.'&comment='.$comment.'&time='.$timeStamp.'&lettermyusername='.$lettermyusername.'">'.$comment.'</a></td></tr>
</table>
<table id="userPostDetails">
<tr><td valign="top" width="100px" class="smallTxt">Author: <em>'.$username.'</em></td><td align="left" valign="top" class="smallTxt">Date Posted:
'.$timeStamp.'</td><td
width=60px align="center" valign="top" class="smallTxt">Views: '.$dbConn->getCounter($postID).'</td><td valign="top" class="smallTxt" align="center">Replies: '.$replies.'</td>
</td></tr>
</table><div class="spacerV11"></div>';
}
//show pages and links
echo "<div align='center'>";
for ($i = 1; $i <= $total_pages; $i++){
$output = ($page == $i) ? $i : '<a href="?page='.$i.'">'.$i.'</a>';
echo $output." "; ***THE PAGE NUMBERS FROM HERE SHOW UP LIKE THEY ARE SUPPOSED TO, BUT AT VERY TOP OF PAGE! I WANT THEM TO SHOW UP AT BOTTOM OF ALL COMMENTS?
}
return $this->value;
}
Then I use the function like this in "index.html":
[code]
include_once ("generatePage.php");
include_once ("dbFunctions.php");
$webPage = new generateHTML();
$dbConn = new dbConnection();
$webPage->addHeader('title', 'PageTitle');
$webPage->addLeftColumn('');
$webPage->addContent('
'.$dbConn->retrieveComments().' *****THIS CALLS ON THE FUNCTION DEFINED ABOVE, ALL SHOWS WELL, EXCEPT FOR THE PAGE NUMBERS, WHICH SHOW AT TOP MOST PART OF PAGE, OUTSIDE OF ALL ELEMENTS?*********
');
$webPage->addFooter(date('Y'), 'SiteSolutions Inc.');
echo $webPage->getPage(); //displays the whole page to browser ?>
What should I do so that the page numbers are displayed inside the content area of the page instead of outside. It just makes it look horrible! If you have any example on how to do this, that would be spamtastic!
return array('content' => $this->value, 'page' => $output);
Of course I wouldn't format those values beforehand with the HTML, but afterward, once they are returned.
See what you can come up with.
By the way, the addContent method simply generates the html layout and takes in some data to be displayed in the middle of the page, in this case, the comments. Thanks again!