动态列选择和多个更新复选框 [英] Dynamic Column Selection and multiple Update checkbox

查看:62
本文介绍了动态列选择和多个更新复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我要做的是我有五个名字:janday1,janday2,janday3,janday4,janday5。



我的网页上有以下声明:



Hi,

What I am trying to do is I have five columns named: janday1, janday2, janday3, janday4, janday5.

I have the statement below in my web page:

$sql = "UPDATE classlog SET janday1 = 'P' ";





我希望更新的列能够根据在名为Pick Column to Update ::的下拉框中选择的列名进行更改。



例如,如果我在下拉框中选择janday1,这意味着我希望更新列janday1,这样当我选中多个更新的复选框时,所有janday1列将更新为'P'。



如果我在下拉框中选择janday2并选中多重更新的复选框,则所有janday2列都将更新到'P'。



如果我在下拉框中选择janday3并且选中多个更新的复选框,所有janday3列都将更新为'P',依此类推。

我想要这个,因为我不想把复选框放到更新每一列。

先生,我可以帮助我。



以下是表格的代码:



I want the updated column to change depending on the column name selected in the drop down box called "Pick Column to Update::".

For example if I select janday1 in the drop down box this means I want column "janday1" to be updated so when I check the checkbox for multiple update, all janday1 column will be updated to ‘P’.

And if I select janday2 in the drop down box and check the checkbox for multiple update, all janday2 column will be updated to ‘P’.

And if I select janday3 in the drop down box and check the checkbox for multiple update, all janday3 column will be updated to ‘P’ and so on.
I want this because I do not want to put checkboxes to update each column.
Sir, I can you help me with this.

Here is the code for the tables:

CREATE DATABASE pathway;

DROP TABLE IF EXISTS pickday;
CREATE TABLE pickday
(dayid BIGINT( 20 )  NOT NULL  AUTO_INCREMENT ,
day_name varchar(15)   ,
PRIMARY KEY (dayid)
);

DROP TABLE IF EXISTS classlog;
CREATE TABLE classlog
(attid BIGINT( 20 )  NOT NULL  AUTO_INCREMENT ,
student_id INTEGER (11)   ,
surname varchar(5)   ,
firstname_other varchar(5)   ,
class_name varchar(5)   ,
janday1 varchar(15)   ,
janday2 varchar(15)   ,
janday3 varchar(15)   ,
janday4 varchar(15)   ,
janday5 varchar(15)   ,
PRIMARY KEY (attid)
);

INSERT INTO  classlog (student_id, surname, firstname_other, class_name) VALUES
(1000,'JOHN','JOHN','BASIC1'),
(1001,'DAVID','DAVID','BASIC2'),
(1002,'BILLY','BILLY','BASIC3'),
(1003,'STEPHEN','STEPHEN','BASIC2'),
(1004,'AHMED','AHMED','BASIC1');





这是php页面的代码:





Here is the code for the php page:

<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("pathway") or die(mysql_error());


$queryData = mysql_query("SELECT * FROM classlog") or die(mysql_error());

if(isset($_GET['P'])){
    $multiple = $_GET['multiple'];


    $i = 0;

    $sql = "UPDATE classlog SET janday1 = 'P' ";

    foreach($multiple as $item_id) {$i ++;
    if ($i == 1) {

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

    } else {

        $sql .= " OR student_id = ".mysql_real_escape_string($item_id)."";
    }

    }
    mysql_query($sql) or die(mysql_error());
    header("location: ".$_SERVER['PHP_SELF']);
    exit();
}

?>

<?php require_once('Connections/con_pathway.php');
mysql_select_db($database_con_pathway, $con_pathway);
$query_pickday = "SELECT * FROM pickday";
$pickday = mysql_query($query_pickday, $con_pathway) or die(mysql_error());
$row_pickday = mysql_fetch_assoc($pickday);
$totalRows_pickday = mysql_num_rows($pickday);

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<link href="school/css/attend.css" rel="stylesheet" type="text/css">
</head>

<body>
<div id="wrapper">
</div><!--close header-->
    <?php if(mysql_num_rows($queryData)>0): ?>
    <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="GET">
    Pick Column to Update::
      <select name="class_group">
          <option value="">Pick Group</option>
          <?php
do {
?>
          <option value="<?php echo $row_pickday['day_name']?>"><?php echo $row_pickday['day_name']?></option>
          <?php
} while ($row_pickday = mysql_fetch_assoc($pickday));
  $rows = mysql_num_rows($pickday);
  if($rows > 0) {
      mysql_data_seek($pickdayp, 0);
      $row_pickday = mysql_fetch_assoc($pickday);
  }
?>
        </select>

      <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <thead>
        <tr>
          <td>ID</td>
          <td>Surname</td>
          <td>First/Othernames</td>
          <td>Class Name</td>
          <td>day1</td>
          <td>day2</td>
          <td>day3</td>
          <td>day4</td>
          <td>day5</td>
          <td align="center">
         <div> <input type="submit" name="P" value="P"></div>
               <input type="checkbox" name="day1" id="day1">
          </td>
        </tr>
        </thead>
        <tbody>
        <?php while ($row = mysql_fetch_assoc($queryData)){?>
        <tr>
          <td><?php echo $row['student_id'] ?></td>
          <td><?php echo $row['surname'] ?></td>
          <td><?php echo $row['firstname_other'] ?></td>
          <td><?php echo $row['class_name'] ?></td>
          <td><?php echo $row['janday1'] ?></td>
          <td><?php echo $row['janday2'] ?></td>
           <td><?php echo $row['janday3'] ?></td>
            <td><?php echo $row['janday4'] ?></td>
             <td><?php echo $row['janday5'] ?></td>
          <td align="center">
          <input type="checkbox" name="multiple[]" value="<?php echo $row['student_id'];?>">
          </td>
        </tr>
        <?php }?>
        </tbody>
      </table>
  </form><!--close form-->
    <?php else: ?>
    <h2> No data to display</h2>
    <?php endif; ?>

</div><!--close wrapper-->
<script type="text/javascript">
    var day1 = document.getElementById('day1');

    day1.onclick = function () {

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

    for (i = 0; i < multiple.length; i ++) {
        multiple[i].checked = this.checked;
    }
    }
</script>

</body>
</html>

推荐答案

sql = UPDATE classlog SET janday1 ='P';





我希望更新的列更改,具体取决于在名为选择要更新的列的下拉框中选择的列名称::。



例如,如果我在下拉框中选择janday1,这意味着我希望更新列janday1,这样当我选中多个复选框时更新后,所有janday1列都将更新为'P'。



如果我在下拉框中选择janday2并选中多重更新复选框,则所有janday2列都将更新为'P'。 br />


如果我在下拉框中选择janday3并选中多次更新的复选框,则所有janday3列都将更新为P,依此类推。

我想要这个,因为我不想让复选框更新每一列。

先生,我可以帮助我。



以下是表格的代码:



I want the updated column to change depending on the column name selected in the drop down box called "Pick Column to Update::".

For example if I select janday1 in the drop down box this means I want column "janday1" to be updated so when I check the checkbox for multiple update, all janday1 column will be updated to ‘P’.

And if I select janday2 in the drop down box and check the checkbox for multiple update, all janday2 column will be updated to ‘P’.

And if I select janday3 in the drop down box and check the checkbox for multiple update, all janday3 column will be updated to ‘P’ and so on.
I want this because I do not want to put checkboxes to update each column.
Sir, I can you help me with this.

Here is the code for the tables:

CREATE DATABASE pathway;

DROP TABLE IF EXISTS pickday;
CREATE TABLE pickday
(dayid BIGINT( 20 )  NOT NULL  AUTO_INCREMENT ,
day_name varchar(15)   ,
PRIMARY KEY (dayid)
);

DROP TABLE IF EXISTS classlog;
CREATE TABLE classlog
(attid BIGINT( 20 )  NOT NULL  AUTO_INCREMENT ,
student_id INTEGER (11)   ,
surname varchar(5)   ,
firstname_other varchar(5)   ,
class_name varchar(5)   ,
janday1 varchar(15)   ,
janday2 varchar(15)   ,
janday3 varchar(15)   ,
janday4 varchar(15)   ,
janday5 varchar(15)   ,
PRIMARY KEY (attid)
);

INSERT INTO  classlog (student_id, surname, firstname_other, class_name) VALUES
(1000,'JOHN','JOHN','BASIC1'),
(1001,'DAVID','DAVID','BASIC2'),
(1002,'BILLY','BILLY','BASIC3'),
(1003,'STEPHEN','STEPHEN','BASIC2'),
(1004,'AHMED','AHMED','BASIC1');





Here is the code for the php page:





Here is the code for the php page:

<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("pathway") or die(mysql_error());



queryData = mysql_query(\"SELECT * FROM classlog\") or die(mysql_error());

if(isset(
queryData = mysql_query("SELECT * FROM classlog") or die(mysql_error()); if(isset(


_GET['P'])){
_GET['P'])){


这篇关于动态列选择和多个更新复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆