【问题标题】:How to get row numbers from MySQL table?如何从 MySQL 表中获取行号?
【发布时间】:2015-04-30 14:32:43
【问题描述】:

所以我在数据库中为我的游戏高分系统制作了这样的表格。

我想获得总行数。 (在上表中,我预计结果为 11)

所以我写在 .php 之类的,

$sql = "SELECT COUNT(*) FROM $table"; 
    $result = mysql_query($sql) or Die('Query failed: ' . mysql_error()); 
    $info = "";
    while($found = mysql_fetch_array($result)){
        $info =  $found;
    }
    echo 'Count'.$info;     exit;

在统一中,我收到上面的回显文本并提取数字,

 if (hs.text.Contains("Count"))
    {
        string result = Regex.Replace(hs.text, @"\D", "");
        totalHighNum = Int32.Parse(result);
        Debug.Log("total highscore num is " + result);
    }

但这不起作用。 打印的回显文本说,'CountArray'

我应该如何复习?谢谢。

【问题讨论】:

    标签: php mysql


    【解决方案1】:

    您必须在结果中引用实际列:

    $sql = "SELECT COUNT(*) AS rowcount FROM $table"; 
    $result = mysql_query($sql) or Die('Query failed: ' . mysql_error()); 
    $info = "";
    if ($found = mysql_fetch_array($result)) {
        $info = $found['rowcount'];
    }
    echo 'Count'.$info;     
    exit;
    

    另外,不要使用mysql 扩展,它已被弃用,切换到mysqli

    【讨论】:

      猜你喜欢
      • 2011-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多