SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How can I pick the checkbox value from an Aarray?

    I have an array mixed of check boxes and hidden fields on a php page.But I have also an action page where I want to display the values from an array. How do I get values from a checked boxes? Please help.

    CODE on the first page

    <td width="14%" align="left" valign="top"><?php echo $nt[RoleId]; ?></td>
    <td width="71%" align="left" valign="top"><?php echo $nt[RoleName]; ?>
    <input name="state[]" type="hidden" id="ID" value="<?php echo $nt[Id]; ?>" /></td>
    <td width="15%" align="left" valign="top"><label>
    <input name="state[]" type="checkbox" id="IDcheckbox" value="1" />

    </label></td>


    Code on the Action Page
    $state=$_POST['state'];
    foreach ($state as $statename)
    {

    echo "$statename[checkbox]";

    }

  2. #2
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How you are storing your check boxes value in to your database? can you show us.

    I mean to say is that if you are storing a field value as comma separated into database and you want to show it as whether these value are ticked(stored) or not.Is that something you want to do?

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do it something like this:
    PHP Code:
    <td width="14%" align="left" valign="top"><?php echo $nt[RoleId]; ?></td>
    <td width="71%" align="left" valign="top"><?php echo $nt[RoleName]; ?>
        <input name="state_name_<?php echo $nt['Id']; ?>" type="hidden" value="<?php echo $nt['statename'];?>" />
    </td>
    <td width="15%" align="left" valign="top">
        <label>
            <input name="states[]" type="checkbox" value="<?php echo $nt['Id'];?>" />
        </label>
    </td>
    And the script:
    PHP Code:
    $states $_POST['states'];
    foreach(
    $states as $state){
        echo 
    $_POST['state_name_' $state] . '<br />';

    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  4. #4
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How about:
    PHP Code:
    <?php foreach($_POST['state'] as $k => $v){ echo $v,'<br>'; } ?>

  5. #5
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is not working, kindly advise. or give an example

  6. #6
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <input name="state[4][hidden]" type="hidden">
    <input name="state[4][checkbox]" type="checkbox">
    <input name="state[99][hidden]" type="hidden">
    <input name="state[99][checkbox]" type="checkbox">
    PHP Code:
    foreach ($_POST['state'] as $v) {
        use 
    $v['hidden'] and $v['checkbox'here

    The hidden field might be redundant, if you could use the id as the 4 or 99 numbers, but I don't know your data.


Bookmarks

Posting Permissions

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