Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 根据其他列的数量创建列基础_Php_Mysql_Mysqli - Fatal编程技术网

Php 根据其他列的数量创建列基础

Php 根据其他列的数量创建列基础,php,mysql,mysqli,Php,Mysql,Mysqli,我想问一下,是否可以在MySQL服务器中创建一个列,根据其他列的数量来包含内容 例如,column name:count,其内容应该是具有相同id的其他列的数量: 表成员:列id和计数 表2:列id和其他 是否可以在member.id中存储表2中与members.id具有相同id的列数 如果没有,我需要创建一个php函数,对表进行计数,并将值存储在members.count中,如: // this should be a for() for every user id // select all

我想问一下,是否可以在MySQL服务器中创建一个列,根据其他列的数量来包含内容

例如,column name:count,其内容应该是具有相同id的其他列的数量:

表成员:列id和计数 表2:列id和其他

是否可以在member.id中存储表2中与members.id具有相同id的列数

如果没有,我需要创建一个php函数,对表进行计数,并将值存储在members.count中,如:

// this should be a for() for every user id
// select all id from members

if ($stmt = $mysqli->prepare("SELECT COUNT(*) rowCount FROM t2 WHERE id = ?")) {
    $stmt->bind_param('ii', $user_id);
    $stmt->execute();
    $stmt->bind_result($rowCount);
    if ($stmt->fetch()) {
        $number_of_rows = $rowCount; // I'm not sure if this variable will store once the stament is closed.
        $stmt->close();
        $stmt = $mysqli->prepare("UPDATE members SET count = ? WHERE id = ?");
        $stmt->bind_param('ii', $number_of_rows, $user_id);
if (! $insert_stmt->execute()) {
    header('Location: /error?err=Registration failure: Contacte al administrador.');
}

    }
我真的不确定,我如何才能做到这一点,如果第一种方法是不可能的,我将感谢一些帮助完成这个功能


提前谢谢

是的,有可能。但一般来说,没有充分的理由,你不应该这样做。e、 g.你有一张很大的桌子,在飞行中运行count*太贵了。你把列和记录搞混了。计数*计数记录。它不计算表中的列。对不起,你是对的。我是说唱片。原因是基于该信息运行脚本。也许还有其他的方法,而且也没那么贵。