我的问题是如何获取一堆选定的复选框项并将仅选择的复选框存储到数据库中。
程序现在运行的方式是使用当前数据,我们可以使用查询将数据填充到屏幕上,并且在我的代码底部有一些我们在表行上调用的特殊函数,其中一个是为每行创建一个隐藏的复选框。当在页面上选择游戏黄色时,选择隐藏复选框。
我想从一系列游戏中进行选择。我想将拥有所选游戏的游戏保存到数据库中。在研究了这个网站上的许多其他问题之后,我还没有得到答案。我所做的是创建一个表单和一个提交输入类型以提交给数据库。我不熟悉如何根据我编写代码的方式制作一个php文件来查询帖子数据,并将所需数据推送到新的模式模型中。
我可以真正使用一些帮助,因为我甚至不知道从哪里开始。感谢大家的帮助。
<?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>";
}
?>
选择游戏的形象: http://s28.postimg.org/50yo5a0jx/Screen_Shot_2014_03_23_at_2_43_27_PM.png
答案 0 :(得分:0)
您有两种选择/解决方案:
如果JS-Function toggleColor 被触发,则创建一个Ajax-Request,否则你必须添加一个隐藏的input-element以通过POST请求发送它。
mysql _ * 已弃用使用PDO或MySQLi