现在我正在尝试编辑我的数据库表的字段,但问题是当我单击它时选择第 1 行,当我第二次单击它时它选择第 2 行,依此类推,无论我选择的是哪一行。
为了便于理解;当我点击第 1 行时,它选择了第一行,但是当我再次点击第 1 行时,它选择了第 2 行并显示了要编辑的第 2 行数据,当我点击第 3 行时,它显示了要编辑的第 3 行数据和儿子。它处于一种循环中。
下面是我的代码
<!doctype HTML>
<head>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="css/venview.css">
</head>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.js"></script>
<input type="button" id="addbtn" value="Add">
<?php
include 'includes/head.php';
include 'ven_connect.php';
include "dashboard.php";
if (isset($_GET["page"]))
{
$page = (int) $_GET["page"];
}
else
{
$page=1;
};
$start_from = ($page-1) * 4;
$result = mysqli_query($conn , "SELECT * FROM vendor LIMIT $start_from, 4") or die (mysqli_error ($conn));
echo "<table title='Vendors'>";
echo '<tr>';
echo "<th>Sr</th>";
echo "<th>Edit</th>";
echo "<th>Delete</th>";
echo "<th>Name</th>";
echo "<th>PhoneNo</th>";
echo "<th>Email</th>";
echo "</tr>";
echo "<tr>";
while($row = mysqli_fetch_array( $result )) {
// display the contents of each row into a table
echo "<tr>";
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . '<img src="edit.png" style = "height:35px;margin-left :8px;" onclick = "edit()">' . '</td>';
echo '<td>' . '<img src="delete.png" style = "height:35px;margin-left :8px;" onclick = "deleterecord('.$row['id'].')">' . '</td>';
echo '<td>' . $row['Name'] . '</td>';
echo '<td>' . $row['Number'] . '</td>';
echo '<td>' . $row['email'] . '</td>';
echo "</tr>";
echo '<div id="dialog-confirm" style="display:none;">';
echo'<form method="post" action="edit_ven.php" class="ajax">';
echo'<label for="id">ID</label>';
echo'<input type="text" id="id" name="id" value= '.$row['id'].' readonly> ';
echo'<label for="name">Name</label>';
echo'<input type="name" id="name" name="name" value= '.$row['Name'].'>';
echo'<label for="number">Number</label>';
echo'<input type="number" id="number" name="number" value= '.$row['Number'].'>';
echo'<label for="email">Email</label>';
echo'<input type="email" id="email" name = "email" value= '.$row['email'].'>';
echo'</form>';
echo'</div>';
}
echo "</tr>";
echo "</table>";
//Pagination!!
if($page > 1)
{
$prev= $page - 1;
echo " <a href='{$_SERVER['PHP_SELF']}?page=$prev'>Prev</a> ";
}
$result = mysqli_query($conn , "SELECT * FROM vendor") or die (mysqli_error ($conn));
$total_records = mysqli_num_rows($result);
$total_pages = ceil($total_records / 4);
$range = 3;
for ($x = ($page - $range); $x <($page + $range); $x++) {
if (($x > 0) && ($x <= $total_pages)) {
if ($x == $page) {
echo " [<b>$x</b>] ";
}
else {
echo " <a href='{$_SERVER['PHP_SELF']}?page=$x'>$x</a> ";
}
}
}
if($page != $total_pages)
{
$nextpage=$page+1;
echo " <a href='{$_SERVER['PHP_SELF']}?page=$nextpage'>Next</a> ";
}
?>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script src="smoke.js"></script>
<link rel="stylesheet" href="css/venview.css">
<script type="text/javascript">
function deleterecord ( id ) {
smoke.confirm("Do you want to delete?", function(result){
if(result)
{
window.location.href = 'delete_ven.php?id=' + id;
}
else{
header("Location: ven_view.php");
}});
}
function edit() {
$('#dialog-confirm').dialog({
modal: true,
width: 400,
height: 400,
buttons: {
update: function() {
window.location.href = 'edit_ven.php?id=' + id;
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
}
</script>
</body>
</html>
最佳答案
您应该发送一个 id 到编辑功能,然后发送 html 代码中的设置。
function edit(id)
关于php - 没有选择正确的行进行编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31229367/
我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib
我好像记得Lua有类似Ruby的method_missing的东西。还是我记错了? 最佳答案 表的metatable的__index和__newindex可以用于与Ruby的method_missing相同的效果。 关于ruby-难道Lua没有和Ruby的method_missing相媲美的东西吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/7732154/
我有一个奇怪的问题:我在rvm上安装了rubyonrails。一切正常,我可以创建项目。但是在我输入“railsnew”时重新启动后,我有“程序'rails'当前未安装。”。SystemUbuntu12.04ruby-v"1.9.3p194"gemlistactionmailer(3.2.5)actionpack(3.2.5)activemodel(3.2.5)activerecord(3.2.5)activeresource(3.2.5)activesupport(3.2.5)arel(3.0.2)builder(3.0.0)bundler(1.1.4)coffee-rails(
我正在查看instance_variable_set的文档并看到给出的示例代码是这样做的:obj.instance_variable_set(:@instnc_var,"valuefortheinstancevariable")然后允许您在类的任何实例方法中以@instnc_var的形式访问该变量。我想知道为什么在@instnc_var之前需要一个冒号:。冒号有什么作用? 最佳答案 我的第一直觉是告诉你不要使用instance_variable_set除非你真的知道你用它做什么。它本质上是一种元编程工具或绕过实例变量可见性的黑客攻击
我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re
question的一些答案关于redirect_to让我想到了其他一些问题。基本上,我正在使用Rails2.1编写博客应用程序。我一直在尝试自己完成大部分工作(因为我对Rails有所了解),但在需要时会引用Internet上的教程和引用资料。我设法让一个简单的博客正常运行,然后我尝试添加评论。靠我自己,我设法让它进入了可以从script/console添加评论的阶段,但我无法让表单正常工作。我遵循的其中一个教程建议在帖子Controller中创建一个“评论”操作,以添加评论。我的问题是:这是“标准”方式吗?我的另一个问题的答案之一似乎暗示应该有一个CommentsController参
我喜欢使用Textile或Markdown为我的项目编写自述文件,但是当我生成RDoc时,自述文件被解释为RDoc并且看起来非常糟糕。有没有办法让RDoc通过RedCloth或BlueCloth而不是它自己的格式化程序运行文件?它可以配置为自动检测文件后缀的格式吗?(例如README.textile通过RedCloth运行,但README.mdown通过BlueCloth运行) 最佳答案 使用YARD直接代替RDoc将允许您包含Textile或Markdown文件,只要它们的文件后缀是合理的。我经常使用类似于以下Rake任务的东西:
我一直致力于让我们的Rails2.3.8应用程序在JRuby下正确运行。一切正常,直到我启用config.threadsafe!以实现JRuby提供的并发性。这导致lib/中的模块和类不再自动加载。使用config.threadsafe!启用:$rubyscript/runner-eproduction'pSim::Sim200Provisioner'/Users/amchale/.rvm/gems/jruby-1.5.1@web-services/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:105:in`co
我需要一些关于TDD概念的帮助。假设我有以下代码defexecute(command)casecommandwhen"c"create_new_characterwhen"i"display_inventoryendenddefcreate_new_character#dostufftocreatenewcharacterenddefdisplay_inventory#dostufftodisplayinventoryend现在我不确定要为什么编写单元测试。如果我为execute方法编写单元测试,那不是几乎涵盖了我对create_new_character和display_invent
大家好!我想知道Ruby中未使用语法ClassName.method_name调用的方法是如何工作的。我头脑中的一些是puts、print、gets、chomp。可以在不使用点运算符的情况下调用这些方法。为什么是这样?他们来自哪里?我怎样才能看到这些方法的完整列表? 最佳答案 Kernel中的所有方法都可用于Object类的所有对象或从Object派生的任何类。您可以使用Kernel.instance_methods列出它们。 关于没有类的Ruby方法?,我们在StackOverflow