TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,970
  • Latest: bynw
Stats
  • Total Posts: 196,055
  • Total Topics: 21,337
  • Online today: 194
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 238
  • Total: 238

Latest Profile Photos

Started by wilsy, November 29, 2007, 08:27:41 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

wilsy

Hi all,

I am using the Ultimate Profile mod from here: -

http://www.simplemachines.org/community/index.php?topic=183574.0

...and wish to display the last five profile photos per member in a front page block.

The code below doesn't format correctly in a front page block. It lists every profile photo and formats them underneath each other rather than in a row across.

It also needs to only list the latest profile photo by member, so if a member uploads 5 new photos at once they dont all show in the block. It will show the latest photo that the last five members have uploaded .....does that make sense?

$pic_number = 5;

global $db_prefix, $modSettings, $scripturl;

$sql = db_query ('SELECT p.ID_PICTURE, p.ID_MEMBER, p.title, p.time, p.filename, m.realName
FROM ' . $db_prefix . 'profile_pictures AS p, ' . $db_prefix . 'members AS m
WHERE p.ID_MEMBER = m.ID_MEMBER
ORDER BY p.time DESC', __FILE__, __LINE__);

$data = array();
while ($row = mysql_fetch_assoc ($sql)) {
$data[] = array (
'title' => $row['title'],
'thumb' => $modSettings['profile_pictures_url'] . '/' . $row['ID_MEMBER'] . '_' . $row['time'] . '_thumb.' . substr (strrchr ($row['filename'], '.'), 1),
'url' => $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . ';sa=pictures;view=' . $row['ID_PICTURE'],
'time' => timeformat ($row['time']),
'user' => $row['realName'],
'profile' => $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
);
}

// now, print the data :)

foreach ($data as $picture) {
echo '<a href="', $picture['url'] ,'"><img src="' . $picture['thumb'] . '" alt="" /><br />' . $picture['title'], '</a>';
}


This is being discusses over at SMF but I thought that as there was something to work with, and there are some superb block experts over here (naming no names - there are far too many!), it might get resolved a little faster at TP ;)

Regards,

Wilsy.

wilsy

#1
Hi,

I've managed to sort the formatting so its all nice and neat. I still cant get it to show only five images though, it shows them all!

This is what I have: -

$pic_number = 5;

global $db_prefix, $modSettings, $scripturl;

$sql = db_query ('SELECT p.ID_PICTURE, p.ID_MEMBER, p.title, p.time, p.filename, m.realName
FROM ' . $db_prefix . 'profile_pictures AS p, ' . $db_prefix . 'members AS m
WHERE p.ID_MEMBER = m.ID_MEMBER
ORDER BY p.time DESC', __FILE__, __LINE__);

$data = array();
while ($row = mysql_fetch_assoc ($sql)) {
$data[] = array (
'title' => $row['title'],
'thumb' => $modSettings['profile_pictures_url'] . '/' . $row['ID_MEMBER'] . '_' . $row['time'] . '_thumb.' . substr (strrchr ($row['filename'], '.'), 1),
'url' => $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . ';sa=pictures;view=' . $row['ID_PICTURE'],
'time' => timeformat ($row['time']),
'user' => $row['realName'],
'profile' => $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
);
}


echo '
<table ALIGN="center">
<tr>';
foreach ($data as $picture)
{
echo '
<td><center>
<a href="', $picture['url'] ,'"><img src="' . $picture['thumb'] . '" alt="" /></a>
</center></td>';
}
echo '
</tr>
</table>';


Regards,

Wilsy.

wilsy

Resolved!

global $db_prefix, $modSettings, $scripturl;
echo '
<a href="', $scripturl ,'?action=profile;u=', $context['user']['id'] ,';sa=pictures;add">Add Profile Photo</a> |  <a href="', $scripturl ,'?action=profile;u=', $context['user']['id'] ,';sa=pictures">My Profile Photos</a>
';
$sql = db_query ('SELECT p.ID_PICTURE, p.ID_MEMBER, p.title, p.time, p.filename, m.realName
FROM ' . $db_prefix . 'profile_pictures AS p, ' . $db_prefix . 'members AS m
WHERE p.ID_MEMBER = m.ID_MEMBER
ORDER BY p.time DESC
LIMIT 5', __FILE__, __LINE__);


$data = array();
while ($row = mysql_fetch_assoc ($sql)) {
$data[] = array (
'title' => $row['title'],
'thumb' => $modSettings['profile_pictures_url'] . '/' . $row['ID_MEMBER'] . '_' . $row['time'] . '_thumb.' . substr (strrchr ($row['filename'], '.'), 1),
'url' => $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . ';sa=pictures;view=' . $row['ID_PICTURE'],
'time' => timeformat ($row['time']),
'user' => $row['realName'],
'profile' => $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
);
}


echo '
<table ALIGN="center">
<tr>';
foreach ($data as $picture)
{
echo '
<td><center>
<a href="', $picture['url'] ,'"><img src="' . $picture['thumb'] . '" alt="" /></a>
</center></td>';
}
echo '
</tr>
</table>';

Zetan


Smoky

very nice!!!  :D  will have to try it out.. thank you..  ;)

Lord Anubis

Nice one Wilsy...That is a sweet mod as well :)

wilsy

Now the last piece of this implementation needs a TP member search block with the following: -

Gender: male/female

Profile Photos: yes/no

...this is way beyond me, can anyone help?

Regards,

Wilsy.

Dragooon

So You want member's Gender and weather he/she have any profile photos or Not in that block?

wilsy

Hi Dragooon,

That would be fantastic, is it possible?

Regards,

Wilsy.

Dragooon

It is easy,
For the Profile Photos Part Use
global $db_prefix, $ID_MEMBER, $settings;
$request = db_query("SELECT ID_PICTURE, ID_MEMBER
FROM {$db_prefix}profile_pictures
WHERE ID_MEMBER = $ID_MEMBER
ORDER BY ID_PICTURE DESC
LIMIT 1",__FILE__, __LINE__);
if(mysql_num_rows($request) > 0)
   echo 'Profile Photos : Yes';
else
   echo 'Profile Photos : No';
mysql_free_result($request);

Now for Gender you can use

$request = db_query("SELECT ID_MEMBER, gender
FROM {$db_prefix}members
WHERE ID_MEMBER = $ID_MEMBER
LIMIT 1",__FILE__,__LINE__);
$row = mysql_fetch_assoc($request);
if($row['gender'] == 1)
{
// The gender is male
echo 'Gender : <img src="',$settings['images_url'],'/Female.gif" />';
}
elseif($row['gender'] == 2)
{
// The gender is male
echo 'Gender : <img src="',$settings['images_url'],'/Male.gif" />';
}

I just wrote this while typing the reply so expect errors :P

This website is proudly hosted on Crocweb Cloud Website Hosting.