chopin Posted April 29, 2022 Posted April 29, 2022 (edited) I created a very simple plugin to query results. My query is this: \IPS\Db::i()->select( '*', 'forums_topics', '(approved = 1) AND (forum_id = 2)', 'rand(), start_date desc limit 5 ) ->join('core_members', 'member_id = starter_id') ); I then run it through a loop: foreach ($sql as $row) { $users[] = \IPS\Member::constructFromData($row); } And finally I return this value to the template: return $this->output($users); The issue is that I am seeing repeat results, even though the query returns unique results. So $sql[0]["tid"] thorugh $sql[4]["tid"] gives me unique results, however $users[0]->tid through $users[4]->tid gives me repeats. I cannot figure out why this is. See attached for an example of the returned results. Is there a better way for me to produce the above? Or is there an issue with the function "\IPS\Member::constructFromData" perhaps? Edited April 29, 2022 by chopin
Jim M Posted April 29, 2022 Posted April 29, 2022 Thanks for posting! Unfortunately, this issue is beyond the scope of our technical support. 👩💻 Our technical support is happy to help you with the Invision Community platform, but we're unable to help with things like server management, theme questions and modifications. I've moved this to our Community Support area where other Invision Community owners will see it and help where they can.
teraßyte Posted April 29, 2022 Posted April 29, 2022 Confused. Do you want a list of topics or members with that code? Because it currently loads multiple topics and joins the members table. If there are multiple topics by the same user you end up with the duplicates in your screenshot. If you want topics you should use: foreach ($sql as $row) { $topics[] = \IPS\forums\Topic::constructFromData($row); } If, instead, you indeed want a list of users then you should check the user hasn't been added to the array already: foreach ($sql as $row) { if (!isset($users[ $row['member_id'] ]) ) { $users[ $row['member_id'] ] = \IPS\Member::constructFromData($row); } } Or change the query that loads the data.
chopin Posted April 29, 2022 Author Posted April 29, 2022 Oh I see the issue. I was using the wrong built in function for what I wanted. It is ok for multiple members to be published, I am looking for topics with few responses. So I would need: \IPS\forums\Topic::constructFromData($row); That should solve my problem, thank you.
Recommended Posts