Solarpitch Posted November 13, 2007 Share Posted November 13, 2007 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! Quote Link to comment Share on other sites More sharing options...
recklessgeneral Posted November 13, 2007 Share Posted November 13, 2007 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. Quote Link to comment Share on other sites More sharing options...
atlanta Posted November 13, 2007 Share Posted November 13, 2007 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(); ?> Quote Link to comment Share on other sites More sharing options...
Solarpitch Posted November 13, 2007 Author Share Posted November 13, 2007 Cheers lads, wrong syntax... stupid me! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.