简体   繁体   English

PHP数据输入(SQL)

[英]PHP data entry (SQL)

I have a form that posts to a PHP page. 我有一个张贴到PHP页面的表单。 This is a snippet of the page. 这是页面的一部分。 The goal is to read out a SQL table and then you click on the text values and they are editable. 目的是读取一个SQL表,然后单击文本值,它们是可编辑的。 You then edit them and submit and it updates the SQL table. 然后,您可以编辑它们并提交,它会更新SQL表。 I basically need a way to strip the letter from the beginning of the id. 我基本上需要一种从ID开头剥离字母的方法。 but the letter is important because it defines in what column the new information goes into. 但是该字母很重要,因为它定义了新信息进入的列。 Also if there is a different language or method to do this, I am open to suggestions. 另外,如果有其他语言或方法可以做到这一点,我也欢迎您提出建议。

<script type="text/javascript">
function exchange(id){
    var ie=document.all&&!window.opera? document.all : 0
    var frmObj=ie? ie[id] : document.getElementById(id)
    var toObj=ie? ie[id+'b'] : document.getElementById(id+'b')
    toObj.style.width=frmObj.offsetWidth+7+'px'
    frmObj.style.display='none';
    toObj.style.display='inline';
    toObj.value=frmObj.innerHTML
}
</script>
<?php
$result = mysqli_query($con,"SELECT * FROM List") or die(mysql_error());
var_dump($_POST);

echo "<table id=list>
<tr id='list_header'>
<th class='list'>ID</th>
<th class='list'>Description</th>
<th class='list'>Winner</th>
</tr><form name='edit' action='inde.php?id=prizes' method='post'>";

while($row = mysqli_fetch_array($result))
{
    echo "<tr>";
    echo "<td class='list'><span id='n" . $row['Number'] . "' onclick='exchange(this.id)'>" . $row['Number'] . "</span><input name='n" . $row['Number'] . "b' id='n" . $row['Number'] . "b' class='replace' type='text' value='" . $row['Number'] . "' style='display:none;'></td>";
    echo "<td class='list'><span id='d" . $row['Number'] . "' onclick='exchange(this.id)'>" . $row['Description'] . "</span><input name='d" . $row['Number'] . "b' id='d" . $row['Number'] . "b' class='replace' type='text' value='" . $row['Description'] . "' style='display:none;'></td>";
    echo "<td class='list'><span id='w" . $row['Number'] . "' onclick='exchange(this.id)'>" . $row['Winner'] . "</span><input name='w" . $row['Number'] . "b' id='w" . $row['Number'] . "b' class='replace' type='text' value='" . $row['Winner'] . "' style='display:none;'></td>";
    echo "<td></td>";

    echo "</tr>";
}
echo "</table><input type='submit' value='Save Changes'></form>";
?>`

From what I understand you have a string id and you want to do the following: 据我了解,您有一个字符串ID,并且您想执行以下操作:

if(strlen($id)>1){
    $important=substr($id, 0, 1); //that gets the important stuff
    $id = ($id, 1, strlen($id)); //that's id without the first char
}
else{
    $important=$id;
    $id=""; //empty string
}

You may want to try Ajax to send the modified values to the server one by one instead of all together at the end. 您可能想尝试Ajax将修改后的值一个接一个地发送到服务器,而不是一并发送到服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM