Results 1 to 3 of 3

Thread: (chekbox)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User Lenor's Avatar
    Join Date: Jan:2009
    Location:
    Posts: 71

    (chekbox)

    . , , ?



    <?php
    mysql_connect("", "", "") or die (mysql_error());
    mysql_select_db("") or die (mysql_error());
    $queryData = mysql_query("SELECT * FROM people") or die (mysql_error());
    if (isset($_GET['delete'])) {

    $multiple = $_GET['multiple'];
    $i = 0;
    $sql = "DELETE FROM people";

    foreach ($multiple as $item_id) { $i ++;

    if ($i == 1) {

    $sql .= " WHERE id = " . mysql_real_escape_string($item_id) . "";

    } else {

    $sql .= " OR id = " .mysql_real_escape_string($item_id) . "";
    }
    }
    mysql_query($sql) or die(mysql_error());

    header("location: " . $_SERVER['PHP_SELF']);

    exit();
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <style type="text/css">
    body { font-family:Verdana, Geneva, sans-serif; font-size:14px; line-height:1.6; text-align:center; color:#000; }
    td { padding:20px; }
    thead { background:#06C; }
    #wrapper { margin:0 auto; width:650px; text-align:left; }
    </style>
    </head>
    <body>
    <div id="wrapper">
    <?php if (mysql_num_rows($queryData) > 0): ?>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">

    <table width="100%">
    <thead>
    <tr>
    <td></td>
    <td></td>
    <td></td>
    <td align="center">
    <div><input type="submit" name="delete" value="Delete Multiple" ></div>
    <input type="checkbox" name="toggle" id="toggle">
    </td>
    </tr>
    </thead>

    <tbody>
    <?php while ($row = mysql_fetch_assoc($queryData)) { ?>
    <tr>
    <td><?php echo $row['first_name'] ?></td>
    <td><?php echo $row['last_name'] ?></td>
    <td><?php echo $row['age'] ?></td>
    <td align="center">
    <input type="checkbox" name="multiple[]" value="<?php echo $row['id']; ?>">
    </td>
    </tr>
    <?php } ?>
    </tbody>




    </table>
    </form>
    <?php else: ?>
    <h2>No data to display </h2>
    <?php endif; ?>
    </div>
    <script type="text/javascript">
    var toggle = document.getElementById('toggle');

    toggle.onclick = function () {

    var multiple = document.getElementsByName('multiple[]');

    for (i = 0; i < multiple.length; i ++) {

    multiple[i].cheked = this.cheked;
    }

    }

    </script>
    </body>
    </html>[/code]

  2. #2
    Registered User
    Join Date: Dec:2003
    Posts: 2,817
    .
    Gigabyte DS3P, E4400@9x333, 2x2Gb Super T@1000Mhz, Gigabyte GTX460OC 768Mb

  3. #3
    Registered User Lenor's Avatar
    Join Date: Jan:2009
    Location:
    Posts: 71
    , : multiple[i].cheked = this.cheked; checked

Posting Permissions

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

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |