从数据库和未定义的索引中获取数据时出错

时间:2014-07-07 05:23:15

标签: pdo fetch

我将值13传递给processpayment.php,但我调用的函数不会向$ req_que_info返回任何值。

<a href="processpayment.php?id=13"</a>

processpayment.php ID = 13:

include("database.php");
$queue_id=$_GET['id'];
$req_que_info = $database->getQueInfo($queue_id);
$count = count($req_que_info); 
echo $req_que_info['queue_id'];
echo $count;

database.php中:

function getQueInfo($queue_id){
   $q = "SELECT * FROM ".TBL_QUEPAY." WHERE queue_id = ?";     
   $stmt = $this->connection->prepare($q);
   $stmt->execute(array($queue_id));
   $dbarray = $stmt->fetchAll();
   return $dbarray;
}

1 个答案:

答案 0 :(得分:0)

因为fetchAll返回一组数组,如

Array
(
    [0] => Array
        (
            [queue_id] => 13
            [name] => foo
            [age] => 99
        )
    [1] => Array
        (
            [queue_id] => 13
            [name] => bar
            [age] => 88
        )
)

fetch一个(单个)数组,如

Array
(
    [queue_id] => 13
    [name] => foo
    [age] => 99
)

尝试

echo $req_que_info[0]['queue_id'];

你可以使用

foreach($req_que_info as $info)
    echo $info . "<br />";

只看到阵列中的什么。

print_r($req_que_info);