Jump to content

[SOLVED] Returning a script of code as a string in an array?


Solarpitch

Recommended Posts

Hey guys,

 

The below code is part of a pagination script in a function. I want to return this section in an array value but I am not sure how its done. I included what I have been trying..

 



        $myinfo = array();

if ($pageno == 1) {
        $printpages = " First Prev ";
} else {
        $printpages =. " <a href='{$_SERVER['PHP_SELF']}?pageno=1&area=".$area."&orderby=".$orderby."'>First</a> ";
        $prevpage = $pageno-1;

        $printpages =. " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage&area=".$area."&orderby=".$orderby."'>Prev</a> ";
}
$printpages =. " ( Page $pageno of $lastpage ) ";
if ($pageno == $lastpage) {
        $printpages =. " Next Last ";
} else {

        $nextpage = $pageno+1;
        $printpages =. " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage&area=".$area."&orderby=".$orderby."'>Next</a> ";
        $printpages =. " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage&area=".$area."&orderby=".$orderby."'>Last</a> ";
} 



    $myinfo[0] .= $printpages;
    return $myinfo;


 

 

I've a feeling I am way off the mark here!

Link to comment
Share on other sites

Hi,

 

First off, a few things immediately jump out at me: The use of =. instead of .= in your string concatenation looks wrong. I tried a sample piece of code using =. and I got parse errors, so I don't know if that was just a typo.

 

Second, you're using the string concatenation operation to assign a string to an array item - again, this looks wrong. Use

$myinfo[0] = $printpages;

 

I'm not sure why you need an array there and not just return a string - maybe you have some constraints on your function signatures?

 

Cheers,

Darren.

Link to comment
Share on other sites

Yea just make it like this

you had the wrong syntax

 

its

.= instead of =.

 

You code would be something like this.

edit it to your scripts variables etc.

<?php
function test()
{ 
\\ set pageno if not set in $_GET['pageno'];
if (!isset($_GET['pageno']))
{
$pageno = 1;
}
else
{
        $pageno = $_GET['pageno'];     
} 

\\last page variable
$lastpage = 15;


if ($pageno == 1) {
        $printpages = " First Prev ";
} else {
        $printpages .= " <a 

href='{$_SERVER['PHP_SELF']}?pageno=1&area=".$area."&orderby=".$orderby."'>First</a> ";
        $prevpage = $pageno - 1;

        $printpages .= " <a 

href='{$_SERVER['PHP_SELF']}?pageno=$prevpage&area=".$area."&orderby=".$orderby."'>Prev</a> 

";
}
$printpages .= " ( Page $pageno of $lastpage ) ";
if ($pageno == $lastpage) {
        $printpages .= " Next Last ";
} else {

        $nextpage = $pageno+1;
        $printpages .= " <a 

href='{$_SERVER['PHP_SELF']}?pageno=$nextpage&area=".$area."&orderby=".$orderby."'>Next</a> 

";
        $printpages .= " <a 

href='{$_SERVER['PHP_SELF']}?pageno=$lastpage&area=".$area."&orderby=".$orderby."'>Last</a> 

";
} 




    echo $printpages;
}
\\ put this where ever you want to call the pagination script above.
test();
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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