Have you set up your custom table for use with xPDO?
I sounds like the 'following' field contains multiple user IDs. Is that true, and if so how are they stored?
When and how is the creation timestamp stored?
Hi BobRay!
Yes, I have all the tables mapped.
The following field is a string comma separated. I'm using explode() to put the values into an array.
The "created" field is a mySQL timestamp.
As always I appreciate the help!
What's the name of your object (The one stored in the table rows)?
You mean the class name? UserPosts
Try this (untested):
$output = '';
$query = $modx->newQuery('UserPosts');
$query->sortby('created','DESC');
$results = $xpdo->getCollection('UserPosts', $query);
if (empty($results)) {
return 'No Data';
}
foreach ($results as $result) {
$fields = $result->toArray();
/* Create output here -- use this first to make sure it's working */
$output .= '<br>' . $fields['created'] . ' -- ' . $fields['following'];
}
return $output;
I think you misunderstood, Bob.
I want to use the array "following" as a property value to get the collection of rows from UserPosts.
Can I pass an array as a property value like...
$query = $modx->newQuery( 'UserPosts' );
$query->sortby( 'created', 'DESC' );
$query->where( 'owner_id', $idArray );
$userStream = $modx->getCollection( 'UserPosts', $query );
The above code won't return any results.
discuss.answer
I just did a facepalm after I finally read the documents on query (was searching the wrong search terms). I was simply missing this ":IN".
For anyone else here is the solution...
$query = $modx->newQuery( 'ClassName' );
$query->sortby( 'created', 'DESC' );
$query->where( 'owner_id:IN', $idArray ); <- the ":IN"
$userStream = $modx->getCollection( 'ClassName', $query );
Bob, thanks again for your timely attention. I apologize for my overlooking the very simple solution and taking up your valuable time. I sincerely appreciate your help, always.
I'm glad you got it sorted.