Welcome Guest, Not a member yet? Register   Sign In
how to access the count?
#1

I have a $result being returned from a sdk call. It has this structure:
$result
   >data {array} [4]
       >Items
         Count
         ScannedCount
      >@metaData

I am trying to get the Count programmatically (I can see it is 12 in the debugger)

$i=$result.data['Count'];
$i=$result->data->Count;

I have tried these plus quite a few others. How can I get $i to equal the the Count?
proof that an old dog can learn new tricks
Reply
#2

why not execute a print_r($result)?

if $result is an object then $i = $result->data['Count']

assuming 'Count' references an item in $data and $data is an array.
Simpler is always better
Reply
#3

$result = $dynamodb->query($params);
$iCount = $result->data['Count'];

I am getting an error:

Message: Cannot access private property Aws\Result::$data

Filename: controllers/Configure.php
proof that an old dog can learn new tricks
Reply
#4

(This post was last modified: 08-19-2018, 08:23 PM by skunkbad.)

Try

$data = $result->getData();

Or

$count = $result->getCount();
Reply
#5

Those two functions don't exist. I can see the count in the result. I can't seem to take a snapshot of the debug window. here is what I see

$result={Aws\result}[1]
data={array}[4]
Items{array}[12]
Count=12

Can I somehow get the size of the items array? that would do it.
proof that an old dog can learn new tricks
Reply
#6

@richb201,

You could also count the items array.
Reply
#7

(08-20-2018, 10:03 AM)php_rocs Wrote: @richb201,

You could also count the items array.

Yes, is there a php function which returns the count of the items (or any) array?
proof that an old dog can learn new tricks
Reply
#8

I tried this but it fails:

$iCount=count($result->data.Items);

$iCount=0

I then tried

$iCount=count($result[data].Items);

and $iCount = 1 instead of 12

I then tried $iCount=count($result['data'].Items);

and $iCount is 1 instead of 12.

Talk about trial and error.....
proof that an old dog can learn new tricks
Reply
#9

Trial and error works!

This worked:

$iCount=$result['Count'];
proof that an old dog can learn new tricks
Reply
#10

(This post was last modified: 08-20-2018, 01:20 PM by php_rocs.)

@richb201,

for items it would be...

$iCount = count($result['Items']);

P.S. Your understanding of how arrays work was the challenge in this situation. I had to work on this issue too. I use to hate working with arrays but once I got the hang of it (more practice) I started to love working with arrays. I'm glad you figured it out.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB