PHP新手难以打印数据库记录
问题描述:
我有一个数据库与第三方,我已经通过他们的API下载它。这里是我的代码:PHP新手难以打印数据库记录
<?php
include_once('./rmapi.class.php');
# initilize class
$rmapi = new RMAPI('mySecretToken');
#request AccountID
$account_info = $rmapi->rm_administrationUsersCurrent();
#parse array and access the account id stdClass object value. returns just the the account GUID as a string
$accountId = $account_info['service_response']->AccountId;
$listId = "mySecretId";
$request = json_decode("{}");
$reportSummary=$rmapi->rm_listsRecipientsFiltered($accountId, $listId, $request);
$data=$reportSummary['service_response'];
$records = count($data);
for ($i = 0; $i < $records; $i++) {
echo "<br />";
echo $i." ";
echo $data[$i]->Email;
echo $data[$i]->lastname;
}
echo "<br />";
?>
这里是什么,我相信是第一个记录:
array(4) { [0]=> object(stdClass)#4 (8) { ["BounceDate"]=> string(20) "0001-01-01T05:00:00Z" ["BounceStatus"]=> string(4) "None" ["CreateDate"]=> string(23) "2017-10-02T14:00:10.41Z" ["Email"]=> string(26) "[email protected]" ["EmailFormatPreference"]=> string(11) "TextAndHtml" ["OptOut"]=> bool(false) ["OptOutDate"]=> string(20) "0001-01-01T05:00:00Z" ["Properties"]=> array(13) { [0]=> object(stdClass)#5 (2) { ["Name"]=> string(5) "email" ["Value"]=> string(26) "[email protected]" } [1]=> object(stdClass)#6 (2) { ["Name"]=> string(9) "firstname" ["Value"]=> string(1) "first" } [2]=> object(stdClass)#7 (2) { ["Name"]=> string(8) "lastname" ["Value"]=> string(1) "last" } [3]=> object(stdClass)#8 (2) { ["Name"]=> string(7) "address" ["Value"]=> string(1) "123 main" } [4]=> object(stdClass)#9 (2) { ["Name"]=> string(4) "city" ["Value"]=> string(1) "anytown" } [5]=> object(stdClass)#10 (2) { ["Name"]=> string(5) "state" ["Value"]=> string(1) "anystate" } [6]=> object(stdClass)#11 (2) { ["Name"]=> string(3) "zip" ["Value"]=> string(1) "00000" } [7]=> object(stdClass)#12 (2) { ["Name"]=> string(5) "phone" ["Value"]=> string(1) "123-456-7890" } [8]=> object(stdClass)#13 (2) { ["Name"]=> string(8) "birthday" ["Value"]=> string(1) "01/01/01" } [9]=> object(stdClass)#14 (2) { ["Name"]=> string(11) "kr_comments" ["Value"]=> string(1) "test comment" } [10]=> object(stdClass)#15 (2) { ["Name"]=> string(10) "lastopened" ["Value"]=> string(21) "10/3/2017 11:41:22 AM" } [11]=> object(stdClass)#16 (2) { ["Name"]=> string(11) "lastclicked" ["Value"]=> string(0) "" } [12]=> object(stdClass)#17 (2) { ["Name"]=> string(10) "createdate" ["Value"]=> string(21) "10/2/2017 10:00:10 AM" } } }
我是新来的PHP,我一直无法打印数据。我试图打印每个记录中的选择字段(即电子邮件,姓氏,名字,电话)。
我将不胜感激。
保重, 比尔
答
在你的循环,你没有价值$记录。你需要:
$records = count($data);
+0
我很抱歉,但我的代码中有这一行。我在发布前清理代码时意外删除了它。我已经更新了我的问题中的代码。 – PapaBurke
在[所以]你应该尝试**自己写代码**。后** [做更多的研究](//meta.*.com/questions/261592)**如果你有问题,你可以**发布你已经尝试**与清楚的解释是什么是'工作**并提供[** Minimal,Complete和Verifiable示例**](// *.com/help/mcve)。我建议阅读[问]一个好问题和[完美问题](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/)。另外,一定要参加[游览]并阅读[this](// meta.*.com/questions/347937/)**。 –
欢迎来到*!你到目前为止尝试过什么吗? *不是一个免费的代码写入服务,并期望你[**尝试首先解决你自己的问题**](http://meta.*.com/questions/261592)。请更新您的问题以显示您已经尝试的内容,在[**最小,完整和可验证的示例**](http://*.com/help/mcve)中展示您面临的特定问题。有关详细信息,请参阅[**如何提出良好问题**](http://*.com/help/how-to-ask),并参加[**网站**之旅](http :) // –