-1

所以..我正在尝试从我的数据库中获取一些数据。

function my_posts(PDO $dbh, $username) {
global $dbh;
$stmt = $dbh->prepare("
    SELECT      *
    FROM        users u
    WHERE       u.user_username = :username
");

$stmt->bindParam(":username", $username);
$stmt->execute();
return $stmt->fetchAll();
}
my_posts($dbh, $username);
$my_posts = my_posts($dbh, $username);

var_dump($my_posts);
var_dump($my_posts['restaurant']);

当我 >var_dump($my_posts);我可以看到我的数据库中的所有内容。但是当我尝试获取特定列时,结果为 null >var_dump($my_posts['restaurant']);

变量转储

怎么来的?

数组(1) { [0]=> 数组(18) { ["user_id"]=> string(1) "1" ["user_username"]=> string(5) "admin" ["restaurant"]=>字符串(21)“zzNabilss Steakhousez”[“logotype”]=>字符串(91)“ http://tipsafilm.se/portfolio-n/projects2013/dinmeny/library/img/restaurants/grillhouse.png ”[“类别” ]=> string(9) "Pizzerior" ["phone"]=> string(11) "0520-213328" ["address"]=> string(20) "Lantmannavägen, 137" ["postal"]= > string(5) "46161" ["city"]=> string(12) "Trollhättan" ["url"]=> string(16) " http://nworks.nu" ["opentimes"]=> string(87) "MÃ¥n-Tors 11.00-21.30, Fre 11.00-22.30, Lör 12.00-22.30, Sönd och helgdag 12.00-21.30" ["pickup"]=> string(1) "1" ["todays"]=> string(1) "0" ["delivery"]=> string(1) "1" ["餐饮"]=> string(1) "1" [ "隐藏"]=> 字符串(1) "0" ["user_created"]=> 字符串(19) "2013-05-25 00:00:00" } }

4

1 回答 1

2

您的结果是一个数组数组;第一个数组用于行,第二个用于列。因此,要获取您使用的第一行$my_posts[0]并获取第一行的餐厅列$my_posts[0]['restaurant']

于 2013-05-26T17:19:27.203 回答