【发布时间】:2014-07-05 08:01:30
【问题描述】:
试图弄清楚如何在结果集中包含行位置的返回值。这是一个非常简单的表,由computer_id 使用 WHERE 子句进行排序。我正在寻找的只是每个结果中的(*row position*) as position。
我通过在 SO 上搜索找到了一些东西,但没有任何东西可以开始工作。
$stmt = $db->prepare("
SELECT *
FROM computers
WHERE account_id = :account_id
ORDER BY computer_id
");
$stmt->bindValue( ':account_id', $_SESSION['user']['account_id'] );
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo '<pre>',print_r($results,1),'</pre>';
【问题讨论】:
-
我猜你是在询问查询返回的每一行的行号?
-
此表的自动递增键字段是否会与您的数据行不明确匹配,或者您是否 gasp 完成了删除操作并使您的键与行位置不同步?跨度>