0

I'm trying to create some next/previous buttons for a form that uses an external XML array. I've split the array into chunks with the plan to navigate between each chunk with the next/previous buttons. I've managed to get it working (sort of) whereby I have corresponding next and previous buttons for each chunk, but I obviously only need one of each button on screen. I fear I may have gone about it the wrong way... Is this perhaps a better job for javascript than php?

Also had a look at this stack question but I can't get any of those solutions working with the array chunks... Any insight is much appreciated.

Many thanks

     <?php
       $xml=simplexml_load_file("../scSHARE/editor.xml");
       $xml_array = (array) $xml;
       $chunks=array_chunk($xml_array["Slot"], 4);
       $i=1;

       foreach($chunks as $bank){ 
     ?>
     <div id="bank_menu" class="menu-item menu-item-<?php echo $i;?>" data-target=".bank_<?php echo $i; ?>">
       <a href="">Next</a>
       <a href="">Prev</a>
     </div>
     <?php $i++;}?>
3
  • You need to pass an offset, chunk number, or page number somehow (typically a URL parameter like ?offset=10), and then you'd need to use that info. Right now, you're not doing any of the above. Commented Dec 14, 2016 at 17:10
  • Have a look at this topic as well. May be it will be in help. Commented Dec 14, 2016 at 17:10
  • Ok, thanks, way over my head though. So Ed you're saying to get rid of the foreach loop and php echos and pass a chunk number in the url where the php echos are, so as to get the current chunk displayed +1/-1 or something? Sorry if thats not at all what you mean I'm still learning and can't quite get my head around what you're saying. Time to read some more about arrays I think Commented Dec 14, 2016 at 17:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.