我只是用數字更新數據庫,但我只希望數字的最後一位數字實際更新。我不確定是否在PHP或MySql中執行此操作。更新mysql,但只有最後一位數字
代碼:(不完整的代碼發佈,但相關的)
if(isset($_POST['update'])) {
$N_Score = $_POST['N_Score'];
$A_Score = $_POST['A_Score'];
$sql = "UPDATE scores SET N_Score = $N_Score, A_Score = $A_Score";
mysql_query($sql) or die(mysql_error());
<form method = "post" action = "<?php $_PHP_SELF ?>">
<table width = "400" border =" 0" cellspacing = "1" cellpadding = "2">
<tr>
<td width = "10"><?php echo $N_Team; ?> Score:</td>
<td><input name = "N_Score" type = "text" id = "N_Score" value="<?php echo $N_Score; ?>"></td>
</tr>
<tr>
<td width = "10"><?php echo $A_Team; ?> Score:</td>
<td><input name = "A_Score" type = "text" id = "A_Score" value="<?php echo $A_Score; ?>"></td>
</tr>
所以,在形式,我進入了N_Team
得分和A_Team
像這樣:
N_Team: 21
& A_Team: 34
我只想要最後一位數字實際進入sql字符串的更新,因此在數據庫中它看起來像這樣:
N_Team: 1
& A_Team: 4
所以你有效嘗試設置分數['值%10'(http://php.net/manual/en/internals2.opcodes。 mod.php)? –
我不這麼認爲,不。 –
爲什麼不呢?按照你的例子,'21%10 = 1'和'34%10 = 4'。 –