1

我正在做一个php项目,

好吧,我需要帮助,比如我有 10 条记录将数据更新到数据库,请参见下面的诊断 -

在此处输入图像描述

现在就像你看到的 No_Info 选项一样,上面写着:No_Data 和 Available。

因此,当用户单击 ID:1 的 No_data 时,它会禁用附加到相应 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>

谁能帮忙解决。。

4

2 回答 2

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'] 作为数组。

于 2013-04-10T08:33:38.457 回答
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
于 2017-08-19T05:03:00.357 回答