php arrays

Discussion in 'HTML' started by wes, Mar 20, 2006.

  1. wes

    wes Guest

    Can i send an array from one php script to another? If so, how?
    Thanks
    Wes
     
    wes, Mar 20, 2006
    #1
    1. Advertising

  2. wes

    Toby Inkster Guest

    wes wrote:

    > Can i send an array from one php script to another? If so, how?


    Not entirely wure what you're asking, but this might be what you're
    looking for...

    <?php
    // file1.php
    $myarray = array(1, 2, 3, 4);
    $mystring = htmlentities(urlencode(serialize($myarray)));
    print "<a href='file2.php?array={$mystring}'>pass it</a>\n";
    ?>

    <?php
    // file2.php
    $myarray = unserialize(stripslashes($_GET['array']));
    print "<pre>";
    var_dump($myarray);
    print "</pre>";
    ?>

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, Mar 21, 2006
    #2
    1. Advertising

  3. wes

    wes Guest

    Thanks, i have a solution that works in a similar way. I have another
    question. I have checkboxes in a php script. The number of checkboxes
    depends on the number of records in my database. So, i want to assign
    the names of each checkbox to an array and send the array (of
    checkboxes) to another php script that will receive the array and
    determine which checkboxes were checked.

    Sounds abit complex, but can anyone tell me if i am allowed to assign
    the names of the checkboxes to an array? its similar to a control array
    in vb

    Wes
     
    wes, Mar 22, 2006
    #3
  4. wes

    Toby Inkster Guest

    wes wrote:

    > Thanks, i have a solution that works in a similar way. I have another
    > question. I have checkboxes in a php script. The number of checkboxes
    > depends on the number of records in my database.


    I'd do something like this:

    <?php
    $i = 0;
    foreach ($database_rows as $r)
    {
    $i++;
    print "<input type=checkbox value=1 name=chk$i>\n";
    }
    print "<input type=hidden value=$i name=nchk>\n";
    ?>

    then the reading script does:

    <?php
    $number_of_checkboxes = $_REQUEST['nchk'];
    for ($i=1; $i<=$number_of_checkboxes; $i++)
    $chk[$i] = $_REQUEST['chk'.$i];
    ?>

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, Mar 22, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ted Zeng
    Replies:
    4
    Views:
    569
    Tim Arnold
    Oct 3, 2006
  2. Ted Zeng
    Replies:
    0
    Views:
    683
    Ted Zeng
    Oct 13, 2006
  3. torque63
    Replies:
    0
    Views:
    664
    torque63
    Jan 1, 2009
  4. Philipp
    Replies:
    21
    Views:
    1,184
    Philipp
    Jan 20, 2009
  5. Rajive Narain
    Replies:
    0
    Views:
    2,081
    Rajive Narain
    Sep 18, 2009
Loading...

Share This Page