【问题标题】:How to access multiple cells from a query result如何从查询结果中访问多个单元格
【发布时间】:2014-04-17 14:03:49
【问题描述】:

使用以下php代码:

$queryfor = "SELECT * FROM entrydata WHERE data_email = '{$email}'";
$resultfor = mysqli_query($connection, $queryfor);
if (!$resultfor){die("Database Failed1!");} 

$rowfor = mysqli_fetch_assoc($resultfor);

如果我使用$rowfor["other_column"],我会从另一列接收数据,该列在其 data_email 列中具有给定的{$email}

** 我的问题是我的 data_email 列中有多行具有相同的电子邮件地址。如何访问我的{$email} 查询的第二个和第三个匹配的“other_column”。 **

我尝试过使用 mysqli_fetch_array 和 $rowfor[x][y] 的组合,但没有成功。

【问题讨论】:

    标签: php sql mysqli fetch


    【解决方案1】:

    mysqli_fetch_array() 一次为一条记录返回一个数组,因此请尝试使用 while 循环进行迭代,例如:

    while($rowfor = mysqli_fetch_array($resultfor))
    {
           echo $rowfor["yourColumnName"]."<br />";
    }
    

    当您的结果集中没有更多行时,mysqli_fetch_array() 将返回 false。

    【讨论】:

      【解决方案2】:

      你可以使用

      while($rowfor = mysqli_fetch_assoc($resultfor))
      {
          if($rowfor["other_column"] == ...)
          {
              ...
          }
      }
      

      访问查询结果的所有列

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-15
        相关资源
        最近更新 更多