php - 如何使用 mysql 数据库列数值添加变量值

标签 php mysql database addition

我需要帮助来添加变量值和数值并且数值是从mysql数据库列获取的?

问题

当我将 std0001 插入 db 列时,函数将无法工作并移至 std0002 否则,如果 db 列中只有数字值,则函数将工作并且移至0002,003.0003

代码

$query = "SELECT snum val FROM students";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);

$new_val = $row['val']+1;
$a='std';
for($i=0; $i <=$new_val; $i++) {

if($new_val == 0) { 
$say=$a.'0'.$i;

} else if($new_val == 1) {
$say=$a.'00'.$i;
}

else
{
$say=$a.'000'.$i;   
}
}

例如我想要喜欢

Std00001
Std00002
Std00003
.
.
.
.
.
.
.
So On...

最佳答案

在您的 JavaScript 中尝试此代码

var a = "00001";
    /*store the value "00001" in a variable as you are getting it from a column*/
var b = "std";
var c = parseInt(a) + 1;
alert(b + c);

关于php - 如何使用 mysql 数据库列数值添加变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19466321/

相关文章:

php - 令人困惑的mysql问题

python - :TypeError: %d format: a number is required, 不是 str:在 python pandas 中给出了偶数

mysql - 数据库设计问题

php - 为什么在同一文件中使用自定义函数时,每次都需要重新连接到数据库?

javascript - 使用javascript从其他php文件获取数据

java - 初始 SessionFactory 创建失败.java.lang.ClassFormatError

php - mysql存储动态列表的最佳方式

php - 在数据库表中只标记一个条目的可能性

PHP $_POST 函数无法识别 HTML 表单输入值

PHP获取实际最大上传大小