Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 是否仅将选定的复选框项添加到数据库?_Php - Fatal编程技术网

Php 是否仅将选定的复选框项添加到数据库?

Php 是否仅将选定的复选框项添加到数据库?,php,Php,我的问题是如何获取一组选中的复选框项目,并将仅选中的项目存储到数据库中 程序现在运行的方式是使用当前数据,我们可以使用查询将数据填充到屏幕上,在代码的底部,我们对表行调用了一些特殊函数,其中之一是为每一行创建一个隐藏的复选框。当游戏在页面上被选择为黄色时,隐藏复选框被选中 我想从游戏列表中进行选择。我想将有选定游戏的游戏保存到数据库中。在这个网站上研究了许多其他类似的问题后,我仍然没有得到答案。我所做的是在上创建一个表单和一个提交输入类型以提交到DB。我不熟悉如何创建一个php文件,根据我编写代

我的问题是如何获取一组选中的复选框项目,并将仅选中的项目存储到数据库中

程序现在运行的方式是使用当前数据,我们可以使用查询将数据填充到屏幕上,在代码的底部,我们对表行调用了一些特殊函数,其中之一是为每一行创建一个隐藏的复选框。当游戏在页面上被选择为黄色时,隐藏复选框被选中

我想从游戏列表中进行选择。我想将有选定游戏的游戏保存到数据库中。在这个网站上研究了许多其他类似的问题后,我仍然没有得到答案。我所做的是在上创建一个表单和一个提交输入类型以提交到DB。我不熟悉如何创建一个php文件,根据我编写代码的方式查询post数据,并将需要的数据推送到一个新的模式模型中

我真的需要一些帮助,因为我甚至不知道从哪里开始。提前感谢大家的帮助

<?php $header= "Upcoming Games"; ?>

<?php include('header.php'); ?>
    <?php
    require_once('dbBaseDao.php');
    require_once('dbGameDao.php');
    require_once('debug.php');

    //@Team: a GameDao is in the dbGameDao.php file and extends BaseDao. I have methods in there to make queries.
    //If you make any new queries, add it to the GameDao class (or *Dao class for new objects)
    $baseDao = new GameDao();

    $resultMw = $baseDao->{'getVsByRoundMW'}(3);
    $resultW = $baseDao->{'getVsByRoundW'}(3);
    $resultS = $baseDao->{'getVsByRoundS'}(3);
    $resultE = $baseDao->{'getVsByRoundE'}(3);

    //$baseDao->display($result);

    $round3 = Array();

    //make array of associative results
    while ($row = mysql_fetch_assoc($resultMw)) $round3[] = $row;

    $keys = Array();

    $keys["Selection"] = "userSelection"; 
    $keys["Game ID"] = "gameID";          
    $keys["Name1"] = "Name1";
    $keys["Name2"] = "Name2";

    $functions = Array();

    $function["upsetPossible"] = "upsetPossible";    
    $function["userSelection"] = "checkbox";     
    $function["gameID"] =  "gameIdClass";    

?><!-- end PHP script --> 

<form action="selected.php" method="POST">              <!-- Test -->

<input type="hidden" name="check_submit" value="1" />   <!-- Test -->


<div class="ui-grid-solo">
    <div class="ui-block-a">
        <a href="#" class="ui-btn ui-corner-all ui-shadow" style="background-color:orange;">Midwest</a><br>
        <span class="numbers"></span>
    </div>
</div>
<table class="unPlayed">
<?php

    foreach ($round3 as $row)
    {

        //@Team this print the columns and also calls the functions
        echo "<tr onclick=\"toggleColor(this);\">";     //tr tag modified by Krish
        foreach (array_keys($keys) as $key)
        {
            $rowName = $keys[$key];
            //@Team this checks if the function is in the functions array, and calls it if it exists in the document
            if (array_key_exists($rowName, $function) && is_callable($function[$rowName]))
            {
                //@Team: $params is something used to send parameters to the function
                //the only param is the row from the database, but is has access to all the columns
                //and can be called by name, e.g. $row['gameId']
                $params = Array();
                $params[] = $row;
                call_user_func_array($function[$rowName], $params);
            }
            //@Team: prints just the data in the row, for the column
            else echo "<td>$row[$rowName]</td>";
        }
        echo "</tr>";
    }
?>
</table>
</br>

<div class="ui-grid-solo">
    <div class="ui-block-a">
        <a href="#" class="ui-btn ui-corner-all ui-shadow" style="background-color:orange;">West</a><br>
        <span class="numbers"></span>
    </div>
</div>
<?php
$round3 = Array();

    //make array of associative results
    while ($row = mysql_fetch_assoc($resultW)) $round3[] = $row;
?>
<table class="unPlayed">
<?php
    //printHeaders($keys);
    foreach ($round3 as $row)
    {
        echo "<tr onclick=\"toggleColor(this);\">";         //tr tag modified by Krish
        foreach (array_keys($keys) as $key)
        {
            $rowName = $keys[$key];
            if (array_key_exists($rowName, $function) && is_callable($function[$rowName]))
            {
                $params = Array();
                $params[] = $row;
                call_user_func_array($function[$rowName], $params);
            }
            else echo "<td>$row[$rowName]</td>";
        }
        echo "</tr>";
    }
?>
</table>

</br>
<div class="ui-grid-solo">
    <div class="ui-block-a">
        <a href="#" class="ui-btn ui-corner-all ui-shadow" style="background-color:orange;">South</a><br>
        <span class="numbers"></span>
    </div>
</div>
<?php
$round3 = Array();

    //make array of associative results
    while ($row = mysql_fetch_assoc($resultS)) $round3[] = $row;
?>
<table class="unPlayed">
<?php
    //printHeaders($keys);
    foreach ($round3 as $row)
    {
        echo "<tr onclick=\"toggleColor(this);\">";     //tr tag modified by Krish
        foreach (array_keys($keys) as $key)
        {
            $rowName = $keys[$key];
            if (array_key_exists($rowName, $function) && is_callable($function[$rowName]))
            {
                $params = Array();
                $params[] = $row;
                call_user_func_array($function[$rowName], $params);
            }
            else echo "<td>$row[$rowName]</td>";
        }
        echo "</tr>";
    }
?>

</table>
</br>

<div class="ui-grid-solo">
    <div class="ui-block-a">
        <a href="#" class="ui-btn ui-corner-all ui-shadow" style="background-color:orange;">East</a><br>
        <span class="numbers"></span>
    </div>
</div>
<?php
$round3 = Array();

    //make array of associative results
    while ($row = mysql_fetch_assoc($resultE)) $round3[] = $row;
?>
<table class="unPlayed">
<?php
    //printHeaders($keys);
    foreach ($round3 as $row)
    {
        echo "<tr onclick=\"toggleColor(this);\">";     //tr tag modified by Krish
        foreach (array_keys($keys) as $key)
        {
            $rowName = $keys[$key];
            if (array_key_exists($rowName, $function) && is_callable($function[$rowName]))
            {
                $params = Array();
                $params[] = $row;
                call_user_func_array($function[$rowName], $params);
            }
            else echo "<td>$row[$rowName]</td>";
        }
        echo "</tr>";
    }
?>
</table>
</br>

<input type="submit" value="Update">

</submitb>
</form>


<?php function printHeaders($keys)
{
    echo "<tr class=\"header\">";
    foreach (array_keys($keys) as $key) echo "<td>$key</td>"; 
    echo "</tr>";
}

function upsetPossible($params)
{
    echo "<td>";
    echo $params["upsetPossible"] == "1" ? "Yes" : "No";
    echo "</td>";
}

function checkbox($params)              //Added by Krish
{
    echo "<td>";
    $id = $params["gameID"];
    echo "<input id=\"$id\" type=\"checkbox\" style=\"display:none\">";
    echo "</td>";
}

function gameIdClass($params)           //Added by Krish
{
    echo "<td class=\"gameID\">";
    echo $params["gameID"];
    echo "</td>";
}

?>









选择游戏的图像:
您有两种选择/解决方案:

如果启动了JS函数toggleColor,则发出Ajax请求,否则必须添加隐藏的输入元素以通过POST请求发送


mysql.*已弃用请使用PDO或MySQLi

谢谢您的回复。我尝试做的是添加一个表单,在该表单中我创建了一个名称操作和方法POST。在每个复选框中,我创建了一个数组gamesSelected的值,并确保所有true for checkbox的值都存储在数组中。你知道我能从这里走到哪里吗?