Cobby Posted June 17, 2007 Share Posted June 17, 2007 Hi all, I am making a pagination system for a CMS. The CMS uses the smarty template engine so I am taking advantage of that. For those who don't know about smarty, anywhere in a code, you can place {tagname} and it will automatically call on the contents of tagname. There is also a little javascript in there aswell (including an include which gets a .js file), but that is irrelevant. so here is the {page} echo "<div class=\"virtualpage5\">"; $i++; variable i will simply how many times the user creates a new page. here is {qpage} echo "</div>"; And this is the actually pagination system. echo " <div id=\"galleryselect\" class=\"paginationstyle\"> <a href=\"#\" rel=\"previous\">Prev</a> <select style=\"width: 120px\"></select> <a href=\"#\" rel=\"next\">Next</a> </div> <script type=\"text/javascript\"> var gallery=new virtualpaginate(\"virtualpage5\", 1) gallery.buildpagination(\"galleryselect\", [\"pages auto appears here"]) //page will automatically. </script> "; What I need, if for every instance of {page} (using $i), to automatically input to the javascript. So if the user had three pages as such: {page} Page 1 {qpage} {page} Page 2 {qpage} {page} Page 3 {qpage} {pagination page1="Page 1" page2="Page 2" page3="3"} And with that, it the script would go: So there is 3 pages. Create a numbered variable for each one (in an array) Input the array into the javascript. And all is dandy. So instead of a long long switch statement. I thought this is where a loop comes into play. This loop I guess should be included in the actual pagination system before the echo. So here is what I have come up with so far: if ($i>0) { $a = "0"; $p = "1"; while ($a<=$i){ $page = array("a => $p"); $page["a"] = $params["a"]; $p++; $a++; } I made two variables a and p. $a is is for the while statement, so i will finish when $a is less than or equal to. $p is to set the page number. But Im not sure if that works. Do I need a foreach statement instead. This topic is sorta confusing, hopefully someone will understand This is the line in the javascript that needs to be defined. gallery.buildpagination(\"galleryselect\", [\"Page 1\", \"Page 2\", \"Page 3\"]) So when the user sets {pagination page1="Page 1" page2="Page 2" page3="Page 3"} those will in fact be the value for the drop down menu to change between pages. I got the original javascript from here -> http://www.dynamicdrive.com/dynamicindex17/virtualpagination.htm I am using Demo Number 5, its the only one with a drop down box. Hope this isn't too confusing, feel free to laugh at me. Thanks, Cobby Link to comment https://forums.phpfreaks.com/topic/55975-avoid-a-long-array-switch-statement-for-pagination/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.