SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Repeating region - radio buttons not working

    OK, I want to update records if an apartment has been rented or not. First step is displaying the records, right? So (using Dreamweaver) I have this:

    PHP Code:
            <?php 
            
    do { ?>
            <tr>
              <td><?php echo $row_rs_rent['unitnum']; ?></td>
              <td><label>
                <input <?php if (!(strcmp($row_rs_rent['rent_status'],"1"))) {echo "CHECKED";} ?> type="radio" name="rent_status" value="1">
            Rented</label>
                  <label>
                  <input <?php if (!(strcmp($row_rs_rent['rent_status'],"0"))) {echo "CHECKED";} ?> type="radio" name="rent_status" value="0">
            Vacant</label>
            </td>
            </tr>
            <?php    } while ($row_rs_rent mysql_fetch_assoc($rs_rent)); ?>
    This displays the unit numbers and radio buttons for each unit. However, only the button for the last record shows a value, everything else is empty. I tried var_dump($row_rs_rent['rent_status']); and got the following:

    string(1) "0"
    string(1) "1"
    string(1) "1"
    string(1) "0"
    string(1) "1"
    string(1) "1"
    string(1) "0"

    which tells me the array is properly filled. So why doesn't it display anything except the last record?

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    All the radio buttons have the same name, which puts them all in the same radio group.
    Only one radio button is allowed to be selected from any radio group.

    You may also want to use a while loop instead of a do..while loop, as currently $row_rs_rent will be empty on the first time through.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I changed the name of the radio buttons to include the unitnum and that worked perfectly. The do..while loops does seem to be fine though, the first record is showing correctly.


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
  •