减去"1"从连续SQL查询中的数字 [英] subtract "1" from the number in a row SQL Query

查看:138
本文介绍了减去"1"从连续SQL查询中的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想知道如何从$ row [posts_remaining]中出现的数字中减去1

I just want to know how to subtract 1 from the number that appears in $row[posts_remaining]

换句话说...

<?php
$con = mysql_connect($db_server_name,$db_username,$db_password);
if (!$con) {
    //do something
}
mysql_select_db("" . $db_database_name . "", $con);
$result = mysql_query("SELECT * FROM users
WHERE fb_id='$user_id'");
while($row = mysql_fetch_array($result)) {
    $posts_remaining = $row['posts_remaining']
    // this is where I want to subtract 1 and then update "posts_remaining" with the new number
}

mysql_close($con);
?>


这将给我我的结果,其中row posts_remaining = {THE NUMBER}


This will give me my result where row posts_remaining = {THE NUMBER}

但是我想更新返回的数字,方法是从中减去一个,然后在旧数字所在的位置设置新数字.

But I want to update that returned number by subtracting one from it and then SETting the new number in back where the old number was.

我希望我不要让这个令人困惑.很难解释.

I hope Im not making this confusing. It's hard to explain.

另外...为了进行此操作,我是否应该将"posts_remaining"行设置为除TEXT之外的其他内容....如Char(50)或其他内容,还是可以将其保留为TEXT?

Additionally... should I have the row "posts_remaining" set as something other than TEXT in order to do this.... like Char(50) or something or is it ok to leave it as TEXT?

推荐答案

首先,您必须将字段的类型从文本修改为整数 比起更新记录,请尝试以下查询

First you have to modify the type of the field from text to integer Than for update records try this query

update users
set
posts_remaining= posts_remaining - 1
WHERE fb_id='your_user_id'

这篇关于减去"1"从连续SQL查询中的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆