Forum Moderators: coopster

Message Too Old, No Replies

Output Syntax

php, syntax, output

         

rodriguez1804

6:08 am on Apr 24, 2009 (gmt 0)

10+ Year Member



Hey guys,

I am trying to output the pages as links in my script, but am having trouble with the output:


for ($i = 1; $i <= $total_pages; $i++){
$output = ($page == $i) ? $i : '<a href="?page='.$i.'">'.$i.'</a>';
echo $output." ";

The problem is it outputs it at the very top of the page. I am trying to get it to output in the content section of the page. I know that I can treat it like a string and then return that string as output, but I am having trouble with the syntax. This is what I have so far:


$output = '';
for ($i = 1; $i <= $total_pages; $i++){
$this->output .= ($page == $i) ? $i : '<a href="?page='.$i.'">'.$i.'</a>';//SO THIS IS THE LINE I THINK I AM SCREWING UP!
return $this->output." ";

This only returns the first page and not as a link. Can anybody tell me what I am doing wrong? Thanks.

andrewsmd

12:20 pm on Apr 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm guessing the reason is, is because this is in a separate file? Where your using a class you need to use something like templates or smarty to put content at different points in the page.

midtempo

2:53 pm on Apr 24, 2009 (gmt 0)

10+ Year Member



how about


$outputString = '';
for ($i = 1; $i <= $total_pages; $i++){
$outputString .= ($page == $i) ? $i : '<a href="?page='.$i.'">'.$i.'</a>';
}

then, later in your page


echo $outputString;

rodriguez1804

9:12 am on Apr 25, 2009 (gmt 0)

10+ Year Member



no, this doesn't quite work midtempo. And yes, this is a separate file, so I ll just play with it some more.