我正在开发一个php项目,
好吧,我需要帮助,比如我有10条记录来更新数据到数据库,请参阅下面的诊断 -
现在就像你看到No_Info选项,说:No_Data和Available。
因此,当用户单击No_data获取ID:1时,它会禁用附加到相应ID的字段。 和相同的可用作品。
但它只适用于ID:1,因为其他行没有工作.....
编辑:在此更新代码。
>>>> <?php
//connect to the database server
$objConnect = mysql_connect("localhost","root","") or die(mysql_error());
//select the database
$objDB = mysql_select_db("main_project");
//select which data you want to get.
$sql = "SELECT * FROM website_maindb";
$objQuery = mysql_query($sql);
// $Ct = mysql_query('select * from company_type');
/* $objResult = mysql_fetch_array($objQuery); // Not to use when using loop to call full database */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>ss</title>
<script>
function disable()
{
document.getElementById("noi1").disabled=true;
document.getElementById("noi2").disabled=true;
document.getElementById("noi3").disabled=true;
document.getElementById("noi4").disabled=true;
document.getElementById("noi5").disabled=true;
document.getElementById("noi6").disabled=true;
}
function enable()
{
document.getElementById("noi1").disabled=false;
document.getElementById("noi2").disabled=false;
document.getElementById("noi3").disabled=false;
document.getElementById("noi4").disabled=false;
document.getElementById("noi5").disabled=false;
document.getElementById("noi6").disabled=false;
}
</script>
</head>
<body>
<form id="form" action="insert.php" method="post">
<table width="700" border="1">
<tr>
<th></th>
<th width="20"> <div align="center">ID </div></th>
<th width="98"> <div align="center">website </div></th>
<th width="98"> <div align="center">category </div></th>
<th width="98"> <div align="center">email </div></th>
<th width="98"> <div align="center">contact form </div></th>
<th width="98"> <div align="center">Primary No. </div></th>
<th width="98"> <div align="center">Secondary No. </div></th>
<th width="98"> <div align="center">fax </div></th>
<th width="98"> <div align="center">Company type </div></th>
<th width="98"> <div align="center">No_Info </div></th>
<th width="98"> <div align="center">time </div></th>
</th>
</tr>
<?php
$options = '';
$Ctype=mysql_query("select distinct typec from company_type");
while($row = mysql_fetch_array($Ctype)) {
$options .="<option>" . $row['typec'] . "</option>";
}
?>
<?php
$i = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$i++;
?>
<tr>
<td><input type="hidden" name="WID" value="<?=$objResult["WID"];?>"></td>
<td><label><input type="text" name="ID" value="<?=$objResult["WID"];?>" disabled></label></td>
<td><input type="text" name="website" value="<?=$objResult["website"];?>"></td>
<td><input type="text" name="cat" size="10"></td>
<td><input type="text" id="noi1" name="email" size="10"></td>
<td><input type="text" id="noi2" name="cform" size="10"></td>
<td><input type="text" id="noi3" name="contactp" size="10"></td>
<td><input type="text" id="noi4" name="contacts" size="10"></td>
<td><input type="text" id="noi5" name="fax" size="10"></td>
<td><select id="Ctype" name="Ctype"> <?=" $options "?> </select></td>
<td><button type="button" onclick="disable()" size="20">No_Data</button> </br>
<button type="button" onclick="enable()" size="20">Available</button>
</td>
<td><input type="text" id="noi6" name="time" size="10"></td>
</tr>
<?php
}
?>
<button type="submit" id="send">Submit</button>
</form>
</table>
</body>
</html>
任何人都可以帮忙解决它..
答案 0 :(得分:1)
你做得有点不对劲。您必须在数组中构建表单字段。像这样:
<input type="text" id="noi1_<?php echo $i; ?>" name="email[]" size="10">
和你的按钮是这样的:
<button type="button" onclick="disable('<?php echo $i; ?>')" size="20">No_Data</button>
然后,在你的JS中:
function disable(idx)
{
document.getElementById("noi1_"+idx).disabled=true;
.
.
。
然后,当你收到$ _POST中的表单时,你会得到$ _POST ['email']作为一个数组。
答案 1 :(得分:0)
**Please Share the Enable code...**
$(document).ready(function() {
$("#submit").click(function() {
var name = $("#name").val();
var cname = $("#cname").val();
var email = $("#email").val();
var contact = $("#contact").val();
var msg = $("#msg").val();
if (name == '' || cname == ''|| email == '' || contact == '' || msg == '') {
alert("Insertion Failed Some Fields are Blank....!!");
} else {
// Returns successful data submission message when the entered information is stored in database.
$.post("re.php", {
name1: name,
cname1: cname,
email1: email,
contact1: contact,
msg1: msg
}, function(data) {
alert(data);
//$('#form')[0].reset(); // To reset form fields
});
}
});
function NextButton() {
mySubmitButton = document.getElementById("submit");
mySubmitButton.click();
myOpenButton = document.getElementById("form1");
myOpenButton.click();
}
$("#submit").click(function(){
$("#name").prop("disabled",true);
$("#cname").prop("disabled",true);
$("#email").prop("disabled",true);
$("#contact").prop("disabled",true);
$("#msg").prop("disabled",true);
});
$("#submit1").click(function() {
var name3 = $("#name3").val();
var cname3 = $("#cname3").val();
var email3 = $("#email3").val();
var contact3 = $("#contact3").val();
var msg3 = $("#msg3").val();
if (name3 == '' || cname3 == ''|| email3 == '' || contact3 == '' || msg3 == '') {
alert("Insertion Failed Some Fields are Blank....!!");
} else {
// Returns successful data submission message when the entered information is stored in database.
$.post("re.php", {
name4: name3,
cname4: cname3,
email4: email3,
contact4: contact3,
msg4: msg3
}, function(data) {
alert(data);
//$('#form')[0].reset(); // To reset form fields
});
}
});
$("#submit1").click(function(){
$("#name3").prop("disabled",true);
$("#cname3").prop("disabled",true);
$("#email3").prop("disabled",true);
$("#contact3").prop("disabled",true);
$("#msg3").prop("disabled",true);
});
});
This code for a disable value coding please share the value enable coding