0

I've been playing around with integrating a mobile app with SimpleDB and am having an problem testing a Select response for emptiness. I'm not much of an OO PHP programmer and am getting confused looking through the code.

Here's the relevant code to grab all of the items I need:

foreach ($duuids as $duuid) {
  $results = null;
  $select_expression = "SELECT * FROM `thestore` WHERE thing IS NOT NULL AND duuid='" . $duuid . "' ORDER BY thing DESC LIMIT 100";

  $next_token = null;

  do {
    if ($next_token)
    {
        $results = $sdb->select($select_expression, array(
            'NextToken' => $next_token,
        ));
    }
    else
    {
        $results = $sdb->select($select_expression);
    }

      foreach ($results->body->Item() as $item) {
        array_push($items, $item);
      }


      $next_token = isset($results->body->SelectResult->NextToken)
        ? (string) $results->body->SelectResult->NextToken
        : null;
  }
  while ($next_token);
}

My problem is that sometimes there isn't any data uploaded yet for a duuid so the result set is empty which breaks the "foreach ($results->body->Item() as $item)" up there.

According to the SDK Docs the select() returns a CFResponse in which $results->body is a SimpleXML document. I've tried some of the methods to count child objects within a SimpleXML document like "$results->body->SelectResult->count()" but that doesn't seem to be working.

Question:
What's the appropriate way to test for emptiness of this result?

aynber
  • 22,380
  • 8
  • 50
  • 63
Stateful
  • 737
  • 2
  • 9
  • 25

2 Answers2

1

Try this:

if($results->body->SelectResult->Item()){
  // process the children
}

You'd think the count() function would work right, but it seems to not do the right thing. Odd that...

Femi
  • 64,273
  • 8
  • 118
  • 148
0

I am not PHP programmer but can give you some idea --

  1. you can check size of attribute map

Select Results >> Get Items >> Check the size of Attribute MAP

  1. you can check select results for null (not confirm whether it will be happened)
Ashish Pancholi
  • 4,569
  • 13
  • 50
  • 88