Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Dynamic button values

    Dynamically pulling data from a database.
    Each record has database field data appearing within a dynamic table, along with several buttons associated to each record.
    All but one of the buttons works correctly.
    "Edit" - opens edit page and passes data related to the respected record.
    "PDF" - opens pdf file and populates it with the respected record.
    "Submit" - Calls a function to generate and send an email.
    "Delete" - Deletes respected record from the database.
    I'm having a problem with the Submit button.
    Presently, the record page shows five records at a time; 1, 2, 3, 4, and 5.
    When the "Submit" button is selected for a any one record, all "Submit" buttons react. (I have an onclick command to change their value to "Submitted".)

    Example:
    Record 3 is the choice record; the user clicks the "Submit" button for record 3. But instead of one email being sent, five emails are sent. (Each "Submit" button changes to "Submitted".)
    All emails do reflect information related to record 3.

    Can dynamic values be created for each button as PHP is pulling data from the database and generating the table? The ideal value generation would look like the following for each "Submit" button. (value="submit1", value="submit2",... value="submit5").

    Not sure if a counter can handle the job.
    Code:
    for($i = 1; $i <= $DBrecords; $i++){
    Something in here
    }

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Well here's the way I'm doing it, though I don't know if it's the best way:

    Code:
    <?php
    for ($i = 0; $i < count($myArray); $i++) {
        print "<input type=\"button\" name=\"subBtn{$i}\" value=\"Submit Record #{$i}\" />\n";
    }
    ?>
    You end up with uniquely named (and labeled) buttons.

  • #3
    Regular Coder
    Join Date
    Jan 2006
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    got it, thanks


  •  

    Posting Permissions

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