【问题标题】:new to PHP and having difficulty printing database recordPHP 新手,难以打印数据库记录
【发布时间】:2017-10-05 23:53:05
【问题描述】:

我有一个第三方数据库,我通过他们的 API 下载了它。这是我的代码:

<?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) "test@test.com" ["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) "test@test.co" } [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 新手,无法打印数据。我正在尝试打印每条记录中的选择字段(即电子邮件、姓氏、名字、电话)。

我将不胜感激。

保重, 比尔

【问题讨论】:

标签: php database printing


【解决方案1】:

在您的 for 循环中,您没有 $records 的价值。你需要:

$records = count($data);

【讨论】:

  • 我很抱歉,但我的代码中有这行。我在发帖前清理代码时不小心删除了它。我已经更新了我的问题中的代码。
猜你喜欢
  • 2021-12-14
  • 1970-01-01
  • 1970-01-01
  • 2018-12-10
  • 2012-04-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多