SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Feb 2002
    Location
    NZ
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using radio buttons to update db

    Never used Radio Buttons before so I'm a bit confused.

    After doing a select there are several rows returned.
    Each row returned can be given a score (using radio buttons) from 1-8

    I'm sure my script thus far is not correct although it seems to work. The other problem is that I cant get the results out.

    The end result should be somewhere along the lines of:
    Bob with an aid of 23 has 8 points
    Terry with an aid of 33 has 7 points
    Gus with an aid of 18 has 3 points
    etc,etc

    I'm not worried about updating the db at this stage I just want to get the results

    Any help appreciated.

    PHP Code:
    <html>
    <head>
    <title>Sports Points Update</title>
    </head>
     
    <body bgcolor="" TOPMARGIN="0" LEFTMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0">
    <form action="weekly_score3.php" method="post">
    <center>
    <table border="1" width="550">
    <tr>
    <td>
    <?php
      
    while ($r2 mysql_fetch_array($result2))
      {
     
    $aid2=$r2['aid'];
       
    $name2 $r2['name'];
    ?>
    <table border="1">
    <tr>
    <td align="left" width="150">
    <?php
    echo $name2;
    ?>
    </td>
    <td width="400">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    1: <input type="radio" name="<?php echo $aid2 ?>" value="1" />
    2: <input type="radio" name="<?php echo $aid2 ?>" value="2" />
    3: <input type="radio" name="<?php echo $aid2 ?>" value="3" />
    4: <input type="radio" name="<?php echo $aid2 ?>" value="4" />
    5: <input type="radio" name="<?php echo $aid2 ?>" value="5" />
    6: <input type="radio" name="<?php echo $aid2 ?>" value="6" />
    7: <input type="radio" name="<?php echo $aid2 ?>" value="7" />
    8: <input type="radio" name="<?php echo $aid2 ?>" value="8" />
    </td>
    </tr>
    <p>
    <?php
    }
    }
    }
    }
    ?>
    <tr>
    <td colspan="2" align="center"><input type="submit" name="update" value="UPDATE" /></td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </center>
    </form>
     
    </body>
    </html>

  2. #2
    SitePoint Addict Trent Reimer's Avatar
    Join Date
    Sep 2005
    Location
    Canada
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should be able to get your results from the $_REQUEST[] variable corresponding to each 'aid'. The one which is selected will be the value which is accepted. You may also want to test that one has been selected.

    In cases like this I normally use arrays to simplify gathering the incoming request variables. A slight modification follows:
    PHP Code:
    1: <input type="radio" name="aid[<?php echo $aid2 ?>]" value="1" />
    2: <input type="radio" name="aid[<?php echo $aid2 ?>]" value="2" />
    //(etc.)
    Then the incoming request variables can be accessed as:
    PHP Code:
    foreach ($_REQUEST['aid'] as $aid=>$points) {
        
    // Since you're working with integers this is an easy test
        
    $points intval($points);
        if (
    $points && $points <= 8) {
            
    // do something amazing here
        
    }


  3. #3
    SitePoint Guru
    Join Date
    Feb 2002
    Location
    NZ
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks dude, worked a treat.


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
  •