简体   繁体   English

如何从MySQL数据库检索行和列的特定组合?

[英]How to retrieve specific combination of row and column from a MySQL database?

I have a database which has an INT column called "registries", and a method that updates this column registries. 我有一个数据库,该数据库具有一个称为“注册表”的INT列,以及一种更新此列注册表的方法。 But first I need to retrieve the data from the specific row/column combination. 但是首先我需要从特定的行/列组合中检索数据。 I was trying to do this in this way: 我试图以这种方式做到这一点:

$result = mysqli_query($link,"SELECT registries FROM product WHERE name = '".$update."'");

Then, the new update variable is, let's say: 然后,新的更新变量为:

$update = $result + 5;

But it doesn't work. 但这是行不通的。 Please, can anybody help me? 拜托,有人可以帮我吗?

The mysqli_query function do not return an integer, returns an object for fetching data. mysqli_query函数不返回整数,返回用于获取数据的对象。

http://www.php.net/manual/en/mysqli.query.php says: http://www.php.net/manual/en/mysqli.query.php说:

For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object 对于成功的SELECT,SHOW,DESCRIBE或EXPLAIN查询,mysqli_query()将返回mysqli_result对象

You have to do this: 您必须这样做:

$resource = mysqli_query($link,"SELECT registries FROM product WHERE name = '".$update."'");
$result = $resource->fetch_object()->registries;
$update = $result + 5;

使用一个查询更新它:

UPDATE products SET registries = registries + 5 WHERE name = '$update'

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

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