Last 5 registered members. -
Face9000 - 17.10.2013
Hello, i've started to work with mysql and i need some help.
I wanna display the last 5 registered members on my site (got already the db and user thing setup), just need the code.
Thank you
Re: Last 5 registered members. -
Konstantinos - 17.10.2013
If you use registered ID for the users, then something like:
pawn Код:
"SELECT `name` FROM `users` ORDER BY `id` DESC LIMIT 5"
Re: Last 5 registered members. -
Face9000 - 17.10.2013
Can you show me the full query? Something like:
Last 5 registered members:
Name 1
Name 2
Name 3
Name 4
Name 5
Also, i use a photo system associated to this user system, how to make it show the profile photo near all the 5 names?
Re: Last 5 registered members. -
Konstantinos - 17.10.2013
That's the query, you'll only need to change the fields' name to your needs (I cannot guess their name).
Then execute the query and loop through the rows, store the names somewhere temporary and do what you wanted to do.
I didn't understand the last one.
Re: Last 5 registered members. -
Face9000 - 17.10.2013
Quote:
Originally Posted by Konstantinos
Then execute the query and loop through the rows, store the names somewhere temporary and do what you wanted to do.
I didn't understand the last one.
|
How i can execute the query? Im a noob with mysql, just started lat week.
About the last one. Every member has his own profile photo, i wanna show it near the last 5 registered members names, got it?
Re: Last 5 registered members. -
tyler12 - 17.10.2013
Assuming you're using PHP. You could do something like:
PHP код:
$query = mysql_query("SELECT * FROM `users` ORDER BY `id` DESC LIMIT 5");
while($row = mysql_fetch_assoc($query))
{
$admin = $row['name'];
$image = $row['image'];
echo "$admin - <img src=\"$image\">";
}
Re: Last 5 registered members. -
Face9000 - 17.10.2013
Quote:
Originally Posted by tyler12
Assuming you're using PHP. You could do something like:
PHP код:
$query = mysql_query("SELECT * FROM `users` ORDER BY `id` DESC LIMIT 5");
while($row = mysql_fetch_assoc($query))
{
$admin = $row['name'];
$image = $row['image'];
echo "$admin - <img src=\"$image\">";
}
|
Ok umh, i was checking my db and i have this tables:
dsb_user_photo
and inside that table, there is the "photo" column, so i guess is where is stored the profile pic of the member.
For username, i have this table:
dsb_user_profiles and there is "_user" column where are stored all the usernames.
So i have to read 2 different tables and 2 different columns.
I made this code to show last 5 registered members (without photo):
PHP код:
$query = mysql_query("SELECT * FROM `dsb_user_profiles` ORDER BY `id` DESC LIMIT 5");
while($row = mysql_fetch_assoc($query))
{
$admin = $row['_user'];
echo "$admin";
}
And this is to show just the photos:
PHP код:
$query = mysql_query("SELECT * FROM `dsb_user_photo` ORDER BY `id` DESC LIMIT 5");
while($row = mysql_fetch_assoc($query))
{
$image = $row['photo'];
echo "<img src=\"$image\">";
}
Now my question is, how to merge this two php codes and make it select two different tables and columns?
Re: Last 5 registered members. -
tyler12 - 17.10.2013
Quote:
Originally Posted by Face9000
Ok umh, i was checking my db and i have this tables:
dsb_user_photo
and inside that table, there is the "photo" column, so i guess is where is stored the profile pic of the member.
For username, i have this table:
dsb_user_profiles and there is "_user" column where are stored all the usernames.
So i have to read 2 different tables and 2 different columns.
I made this code to show last 5 registered members (without photo):
PHP код:
$query = mysql_query("SELECT * FROM `dsb_user_profiles` ORDER BY `id` DESC LIMIT 5");
while($row = mysql_fetch_assoc($query))
{
$admin = $row['_user'];
echo "$admin";
}
And this is to show just the photos:
PHP код:
$query = mysql_query("SELECT * FROM `dsb_user_photo` ORDER BY `id` DESC LIMIT 5");
while($row = mysql_fetch_assoc($query))
{
$image = $row['photo'];
echo "<img src=\"$image\">";
}
Now my question is, how to merge this two php codes and make it select two different tables and columns?
|
PHP код:
$query = mysql_query("SELECT * FROM `dsb_user_profiles` ORDER BY `id` DESC LIMIT 5");
while($row = mysql_fetch_assoc($query))
{
$admin = $row['_user'];
$querya = mysql_query("SELECT * FROM `dsb_user_photo` WHERE `_name` = '$admin'");
while($rowa = mysql_fetch_assoc($querya))
{
$image = $rowa['photo'];
}
echo "$admin<br>";
echo "<img src=\"$image\"><br>";
}
Re: Last 5 registered members. -
gtakillerIV - 17.10.2013
You can try union select.
PHP код:
$query = mysql_query("(SELECT * FROM `dsb_user_profiles` LIMIT 5) UNION (SELECT * FROM `dsb_user_photo` LIMIT 5) ORDER BY `id` DESC");
while($row = mysql_fetch_assoc($query))
{
$admin = $row['_user'];
$image = $row['photo'];
echo "$admin";
echo "<img src=\"$image\">";
}
If you don't care about duplicates, then do:
PHP код:
$query = mysql_query("(SELECT * FROM `dsb_user_profiles` LIMIT 5) UNION ALL (SELECT * FROM `dsb_user_photo` LIMIT 5) ORDER BY `id` DESC");
while($row = mysql_fetch_assoc($query))
{
$admin = $row['_user'];
$image = $row['photo'];
echo "$admin";
echo "<img src=\"$image\">";
}
Re: Last 5 registered members. -
Face9000 - 17.10.2013
Ok, im using a html page to show everything, and i included this code in my html page (full code):
Код:
<?php $query = mysql_query("SELECT * FROM `dsb_user_profiles` ORDER BY `id` DESC LIMIT 5");
while($row = mysql_fetch_assoc($query))
{
$admin = $row['_user'];
$querya = mysql_query("SELECT * FROM `dsb_user_photo` WHERE `_name` = '$admin'");
while($rowa = mysql_fetch_assoc($querya))
{
$image = $rowa['photo'];
}
echo "$admin<br>";
echo "<img src=\"$image\"><br>";
} ?>
But i dont get why it shows just:
"; echo "
"; } ?>"
Whats wrong?