Osclass forums
Support forums => General help => 3.8.x => Topic started by: elizabeth 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
-
ok i found this in the forum:
<?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 ????
-
Hello!
Welcome to Osclass forums! :)
Try this code:
<?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.
-
Hello!
Welcome to Osclass forums! :)
Try this code:
<?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?
-
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.
-
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
-
Depends... Which avatar plugin you use?
Regards.