Results 1 to 9 of 9

Thread: checkboxes..

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2002
    Location
    CT
    Posts
    62

    checkboxes..

    My problem is this: I am pulling information from the database and it is stored in a table on the screen. I want to add a checkbox next to each line so that if there are multiple john does in the database the user can decide which john doe he needs to edit by clicking on the checkbox and then clicking submit. Any help would be appreciated. Thanks
    Sometimes the simplest things are the hardest...

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    What part of this do you need help with?

    Make each checkbox an array:

    Code:
    <input type="checkbox" name="edit[]" value="id_of_record">John Doe 1
    <input type="checkbox" name="edit[]" value="id_of_record">John Doe 2
    <input type="checkbox" name="edit[]" value="id_of_record">John Doe 3
    And in your code for the submit:

    Code:
    for ($i = 0; $i < count($_REQUEST['edit']); $i++) {
        //edit the record
    }
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2002
    Location
    CT
    Posts
    62

    checkboxes

    Part of my problem is the checkboxes are appearing at the top of the screen instead of next to the item in the loop. and also, the checkboxes are not all working, only the first one. Ive spent time on and off playing with this and the books that I have are not helpful in this area, thats why I asked you guys. Thanks
    Sometimes the simplest things are the hardest...

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Could you post the code you have now so we could help find the problems in it?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2002
    Location
    CT
    Posts
    62

    code

    this is the piece of code I have been working on:

    while ($Row = mysql_fetch_array($Result))
    {
    print ("<TR Align=center Valign=top>\n");
    print ("<TD Align=center Valign=top>$Row[social]</TD>\n");
    print ("<TD Align=center Valign=top>$Row[lname]</TD>\n");
    print ("<TD Align=center Valign=top>$Row[fname]</TD>\n");
    print ("<TD Align=center Valign=top>$Row[address]</TD>\n");
    print ("<TD Align=center Valign=top>$Row[state]</TD>\n");
    print ("<TD Align=center Valign=top>$Row[Zip]</TD>\n");
    print ("<TD Align=center Valign=top>$Row[region_code]</TD>\n");
    print ("<TR>\n");
    $array[$x] = $Row[social];
    $x=$x+1;
    <form method="post" action="submitupdateuserinfo.php">
    ?>
    <input type="checkbox" name="cart[]" value=<?$array[x]?>>
    <input type="submit" name="b1" value="submit">
    </form>
    }
    print "</table>\n";
    <?


    what i want to happen is to have the checkboxes print out at the end of each line, becuase what this is doing is querying a database against user input, so for example if i enter in a first 3 digits of my last name, and there are 5 other people in the database whose last names start with the same 3 charachters as mine, it will return 5 names. I want a checkbox after each set of data that I can just click on and have it bring up more information on that particular user. Is what im saying possible? thanks
    Sometimes the simplest things are the hardest...

  6. #6
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: code

    Code:
    echo '<form method="post" action="submitupdateuserinfo.php">';
    while ($Row = mysql_fetch_array($Result)) {
      echo '<TR Align=center Valign=top>
          <TD Align=center Valign=top>' . $Row['social'] . '</TD>
          <TD Align=center Valign=top>' . $Row['lname'] . '</TD>
          <TD Align=center Valign=top>' . $Row['fname'] . '</TD>
          <TD Align=center Valign=top>' . $Row['address'] . '</TD>
          <TD Align=center Valign=top>' . $Row['state'] . '</TD>
          <TD Align=center Valign=top>' . $Row['Zip'] . '</TD>
          <TD Align=center Valign=top>' . $Row['region_code']</TD>';
    
      $array[] = $Row['social]';
      $x=$x+1;
      
          echo '<TD Align=center Valign=top>
          <input type="checkbox name="cart[] value="' . $array[$x] . '"></td>
        </tr>';
    }
    
    echo '</table><input type="submit"></form>';
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7

    Thread Starter
    Member
    Join Date
    Feb 2002
    Location
    CT
    Posts
    62

    thanks

    I was able to get everything to work with the code that you gave me.. if i might ask thouhg.. what do all the periods do? I noticed that was the main differnece between yours and mine? what are they there for? Thanks a lot
    Sometimes the simplest things are the hardest...

  8. #8
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    The . is the string concatenator. So:

    Code:
    $var1 = "cunch";
    echo "Varable #1 = " . $var1 . "<br>";
    Will out put "Variable #1 = cunch<br>"

    If you use double quotes, though, you can just do:

    Code:
    $var1 = "cunch";
    echo "Variable #1 = $var1<br>";
    It's just my coding preference.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  9. #9

    Thread Starter
    Member
    Join Date
    Feb 2002
    Location
    CT
    Posts
    62

    coding

    Cool, thanks for the info... the code that you gave me makes a lot more sence to me now.
    Sometimes the simplest things are the hardest...

Posting Permissions

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



Click Here to Expand Forum to Full Width