Advertisement:

Author Topic: Question about a function or plugin.  (Read 369 times)

elizabeth

  • Newbie
  • *
  • Posts: 37
Question about a function or plugin.
« on: February 03, 2019, 03:18:34 pm »
Hello and congratulations for this awesome platform. I just installed osclass locally and this is my first post here. I would like to ask you if there is any function/option or a plugin to display the latest eg 10 users registered on my website. I mean at the frontend home page under the latest listings for example.

I looked into admin panel but there isn't such an option.

Thanks

elizabeth

  • Newbie
  • *
  • Posts: 37
Re: Question about a function or plugin.
« Reply #1 on: February 03, 2019, 04:42:53 pm »
ok i found this in the forum:
Code: [Select]
<?php $users User::newInstance()->listAll();
$users array_reverse($users);

foreach(
$users as $user) { 

echo 
'<strong>Username</strong>: ' '<a href="user/profile/'$user['pk_i_id'] . '">' $user['s_name'] . '</a>' '<br /> ';

?>

BUT this code display all users. How can i limit the resuts to 8 or 10 ????

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Question about a function or plugin.
« Reply #2 on: February 03, 2019, 05:06:19 pm »
Hello!

Welcome to Osclass forums! :)

Try this code:

Code: [Select]
<?php
$dao 
= new DAO(); // Osclass data access object.
$query $dao->dao->query(sprintf('SELECT * FROM %st_user ORDER BY dt_reg_date DESC LIMIT 10'DB_TABLE_PREFIX)); // Perform query.
if(count($query)) { // If there is data that matches query
    
$users $query->result(); // Save it in $users variable.
} else { // Else
    
$users null// save null to $users variable.
}
foreach(
$users as $user) { // Loop through users.
    
echo '<strong>Username</strong>: ' '<a href="user/profile/'$user['pk_i_id'] . '">' $user['s_name'] . '</a>' '<br /> ';
}
?>


Regards.

elizabeth

  • Newbie
  • *
  • Posts: 37
Re: Question about a function or plugin.
« Reply #3 on: February 03, 2019, 10:00:29 pm »
Hello!

Welcome to Osclass forums! :)

Try this code:

Code: [Select]
<?php
$dao 
= new DAO(); // Osclass data access object.
$query $dao->dao->query(sprintf('SELECT * FROM %st_user ORDER BY dt_reg_date DESC LIMIT 10'DB_TABLE_PREFIX)); // Perform query.
if(count($query)) { // If there is data that matches query
    
$users $query->result(); // Save it in $users variable.
} else { // Else
    
$users null// save null to $users variable.
}
foreach(
$users as $user) { // Loop through users.
    
echo '<strong>Username</strong>: ' '<a href="user/profile/'$user['pk_i_id'] . '">' $user['s_name'] . '</a>' '<br /> ';
}
?>


Regards.

Thank you so much for your answer Patrick. Just 2 more questions Does your code limit the results to the 10 latest registered users? Also is it safe to make queries like that in database?

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Question about a function or plugin.
« Reply #4 on: February 03, 2019, 11:51:03 pm »
If you want more than 10 just increase the number, for example, if you want 20 users then use "LIMIT 20".

DAO class takes care of security. User class you used in your code is just an "extension" of DAO class.

Regards.

elizabeth

  • Newbie
  • *
  • Posts: 37
Re: Question about a function or plugin.
« Reply #5 on: February 05, 2019, 07:50:15 pm »
If you want more than 10 just increase the number, for example, if you want 20 users then use "LIMIT 20".

DAO class takes care of security. User class you used in your code is just an "extension" of DAO class.

Regards.

Patrick is there also a simple way to display the avatar of the users before their username ?
Regards

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Question about a function or plugin.
« Reply #6 on: February 05, 2019, 08:25:20 pm »
Depends... Which avatar plugin you use?

Regards.