Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2006
    Location
    D?sseldorf
    Posts
    2,858
    Tokens
    2,256

    Latest Awards:

    Default Help! Not sure how to do something..

    I'm absolutely stumped by this so I'll try and explain it the best I can.

    I'd like to make an attendance system for a web app I'm making (nothing public, just a closed personal system). I want to grab all the data from the 'users' table and display the 'forename' and 'surname' on a table. Then each 'name' will have a radio button group. Like this:

    PHP Code:
    <?php
    include "functions.php";
    $query "SELECT * FROM users ORDER by surname ASC";
    $result mysql_query($query) or die(mysql_error());
    $row mysql_fetch_assoc($result);
    ?>
    <table>
    <tr>
    <td>Name</td>
    <td colspan="5"></td>
    </tr>
    <form id="form" name="form" method="post" action="process.php">
    <?php do { ?>
    <tr>
    <td><?php echo $row['forename']. ' ' .$row['surname']; ?></td>
    <td><input type="radio" name="<?php echo $row['id']; ?>" id="<?php echo $row['id']; ?>_PU" value="PU" >PU</td>
    <td><input type="radio" name="<?php echo $row['id']; ?>" id="<?php echo $row['id']; ?>_PC" value="PC">PC</td>
    <td><input type="radio" name="<?php echo $row['id']; ?>" id="<?php echo $row['id']; ?>_AA" value="AA">AA</td>
    <td><input type="radio" name="<?php echo $row['id']; ?>" id="<?php echo $row['id']; ?>_S" value="S">S</td>
    <td><input type="radio" name="<?php echo $row['id']; ?>" id="<?php echo $row['id']; ?>_AWOL" value="AWOL">AWOL</td>
    </tr>
    <?php } while ($row mysql_fetch_assoc($result)); ?> 
    </form>
    </table>
    Now, what would I have to do, so that when I press the submit button, it will get all this data, and add the data to a table called attendance? I want the table to look something like this

    id user_id record date
    *AI* 1 (or row['id']) PU (or one of the radio buttons) CURRENT_TIMESTAMP

    with the id and date being automatic.

    Can anyone shed any light? I'm pretty new to this and just tinkering around

    Many thanks in advance

  2. #2
    Join Date
    Nov 2006
    Location
    D?sseldorf
    Posts
    2,858
    Tokens
    2,256

    Latest Awards:

    Default

    I figured it out. For anyone interested:

    PHP Code:
    <?php
    include "functions.php";
    $query "SELECT * FROM users ORDER by surname ASC";
    $result mysql_query($query) or die(mysql_error());
    $row mysql_fetch_assoc($result);
    ?>
    <table>
        <tr>
            <td>Name</td>
            <td colspan="5"></td>
        </tr>

    <tbody>
        <form id="form" name="form" method="post" >
        <?php
            $idx  
    0;
            do { 
        
    ?>
            <tr>
                <td><?php echo $row['forename']. ' ' .$row['surname']; ?></td>
                <td><input type="radio" name="radioName[<?php echo $idx?>]" value="PU" >PU</td>
                <td><input type="radio" name="radioName[<?php echo $idx?>]" value="PC">PC</td>
                <td><input type="radio" name="radioName[<?php echo $idx?>]" value="AA">AA</td>
                <td><input type="radio" name="radioName[<?php echo $idx?>]" value="S">S</td>
                <td><input type="radio" name="radioName[<?php echo $idx?>]" value="AWOL">AWOL</td>
            </tr>
            <input type = "hidden" value = "<?php echo $row['id']; ?>" name="userId[<?php echo $idx?>]">

            <?php $idx ++; ?>
            <?php } while ($row mysql_fetch_assoc($result)); ?> 
    </tbody>
            <input type = "submit" value = "Register" >
        </form>

    </table>


    </br>
    <?php 

    if (isset($_POST['radioName'][0])) {
        
        foreach (
    $_POST['radioName'] as $index => $value) {
            

            if (empty(
    $value)) {
                echo 
    "You must select the radio button.";
                break;
            }
            
    $record $_POST['radioName'][$index];
            
    $userId $_POST['userId'][$index];
            
            
    $query "INSERT INTO attendance(user_id, record, date)
            VALUE ('
    $userId','$record', NOW())";
            
    $result mysql_query($query) or die('Query failed: ' mysql_error());
        }
        echo 
    "Data stored successly!";
    }

    ?>

Posting Permissions

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