Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2003

    Question Unanswered: Posting Multi-dimension named arrays with a form

    I have an array which fetches from mysql, this is the array:

    $results[$i] = array('studno' => $row[0], 'name' => $row[1], 'surname' => $row[2], 'cell' => $row[3], 'email' => $row[4], 'course' => $course, 'campus' => $campus, 'img' => $row[7]);

    It goes on a results page viewing 5 results at a time, now i want to pass the array back to itself when a person hits next page so they can view say results 5-10, then again for 10-15 etc.

    I have seen it mentioned that you can implode the array and assign it to a hidden input variable on the form, and then explode it back into an array. i have tried this but it does not come up with the correct information, just a whole lot of single charactered values for each item.

    How would i be able to pass this array ?

  2. #2
    Join Date
    Sep 2003
    Wisconsin, USA

    php/html arrays

    You can use arrays in html just by setting the input element's names to the array values.

    For example, we have this array
    $myarray = array('thing1'=>'value1', 'thing2'=>'value2');

    to represent this in html you'd have:
    <input type="hidden" name="htmlarray['thing1']" value="value1"/>
    <input type="hidden" name="htmlarray['thing2']" value="value2"/>

    Now when you want to read this back in on the page you submitted to, just do:
    $myarray = $_POST['htmlarray'];

    now $myarray in the second page is the same as the first! Piece of cake!

    You can do this with multi-dimensional arrays too.
    <input type="hidden" name="htmlarray['dim1key1']['dim2key1']" value="Value-For-Dimension1Key1-Dimension2key1""/>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts