Twitter SMFHacks Facebook SMFHacks SMFHacks.com
** Home Forum Index Hacks Products Login Register Search
Welcome, Guest. Please login or register.
May 19, 2013, 05:14:59 pm

Login with username, password and session length
Members
Total Members: 10758
Latest: murdocklawless
Stats
Total Posts: 32349
Total Topics: 5474
Online Today: 60
Online Ever: 2482
(April 09, 2011, 07:02:45 pm)
Users Online
Users: 1
Guests: 44
Total: 45
+ 
|-+ 
| |-+ 
| | |-+ 
| | | |-+ 
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] 2 Go Down Print
Author Topic: Badges Displayed in Profile  (Read 1234 times)
shuban
Badge Awards Customer
Full Member
*****
Offline Offline

Posts: 163


View Profile WWW
« on: June 02, 2012, 02:58:08 pm »

I purchased the software, at your convenience, could you provide me the profile.template.php code that displays all the badges earned?

Thank you Grin
Logged

SMFHacks
Administrator
Hero Member
*****
Offline Offline

Posts: 10987


View Profile
« Reply #1 on: June 02, 2012, 03:04:20 pm »

Try this
Example code with caching. Just need to pass in/set $memberID

Code:
global $modSettings, $db_prefix, $boardurl;

if (empty($modSettings['badgeawards_url']))
$modSettings['badgeawards_url'] = $boardurl . '/badges/';
       
$badgesCache = array();
if (($badgesCache = cache_get_data('badge_display_' . $memberID, 60)) == null)
{

$result = db_query("
SELECT
b.id_badge, b.title, b.image, b.enabled, l.date
FROM ({$db_prefix}badgeawards_badges as b, {$db_prefix}badgeawards_badge_log as l)
WHERE l.id_badge = b.id_badge AND l.ID_MEMBER = $memberID
ORDER BY l.id_log DESC
LIMIT  $maxToShow
", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($result))
{
$badgesCache[] = $row;

}

cache_put_data('badge_display_' . $memberID, $badgesCache, 60);

}


// Tweak this loop for display
foreach($badgesCache as $row)
{
echo '<img src="' . $modSettings['badgeawards_url']  . $row['image'] . '" alt="' . $row['title'] . '" title="' . $row['title'] . '" /> ';

}
['code]
Logged
shuban
Badge Awards Customer
Full Member
*****
Offline Offline

Posts: 163


View Profile WWW
« Reply #2 on: June 02, 2012, 03:21:35 pm »

Got an error

Code:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY l.id_log DESC
LIMIT' at line 5
File:

SELECT
         b.id_badge, b.title, b.image, b.enabled, l.date
      FROM ({$db_prefix}badgeawards_badges as b, {$db_prefix}badgeawards_badge_log as l)
      WHERE l.id_badge = b.id_badge AND l.ID_MEMBER = $memberID
      ORDER BY l.id_log DESC
      LIMIT  $maxToShow
      ", __FILE__, __LINE__);
      while ($row = mysql_fetch_assoc($result))

Line 998 is ", __FILE__, __LINE__);
Logged

SMFHacks
Administrator
Hero Member
*****
Offline Offline

Posts: 10987


View Profile
« Reply #3 on: June 02, 2012, 03:23:56 pm »

Remove
LIMIT  $maxToShow
Logged
shuban
Badge Awards Customer
Full Member
*****
Offline Offline

Posts: 163


View Profile WWW
« Reply #4 on: June 02, 2012, 03:26:52 pm »

Now I get this:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY l.id_log DESC' at line 5

Code:
$result = db_query("
SELECT
b.id_badge, b.title, b.image, b.enabled, l.date
FROM ({$db_prefix}badgeawards_badges as b, {$db_prefix}badgeawards_badge_log as l)
WHERE l.id_badge = b.id_badge AND l.ID_MEMBER = $memberID
ORDER BY l.id_log DESC
", __FILE__, __LINE__);

Error on ", __FILE__, __LINE__);

This is for 1.x
Logged

SMFHacks
Administrator
Hero Member
*****
Offline Offline

Posts: 10987


View Profile
« Reply #5 on: June 02, 2012, 03:28:59 pm »

Are you setting $memberID = to anything before calling the query?
It should be set to the member id of the profile you are viewing.
Logged
shuban
Badge Awards Customer
Full Member
*****
Offline Offline

Posts: 163


View Profile WWW
« Reply #6 on: June 02, 2012, 03:31:11 pm »

No, what do I set $memberID to?
Logged

shuban
Badge Awards Customer
Full Member
*****
Offline Offline

Posts: 163


View Profile WWW
« Reply #7 on: June 02, 2012, 03:33:06 pm »

HEre's my profile.template...

I added the code to it already, just search for it...
« Last Edit: June 02, 2012, 03:42:04 pm by shuban » Logged

SMFHacks
Administrator
Hero Member
*****
Offline Offline

Posts: 10987


View Profile
« Reply #8 on: June 02, 2012, 03:35:48 pm »

Before
$badgesCache = array();   
Add
Code:
$memberID = $context['member']['id'];
Logged
shuban
Badge Awards Customer
Full Member
*****
Offline Offline

Posts: 163


View Profile WWW
« Reply #9 on: June 02, 2012, 03:41:50 pm »

Before
$badgesCache = array();   
Add
Code:
$memberID = $context['member']['id'];

Looks great... Smiley
Logged

shuban
Badge Awards Customer
Full Member
*****
Offline Offline

Posts: 163


View Profile WWW
« Reply #10 on: June 02, 2012, 05:23:56 pm »

If I disable a badge, is it possible to not have it show up in people's profiles who have already earned it?

For instance, I disabled the "Level 1 Badge", but it's still showing up in people's profiles that they still have it Embarrassed
Logged

SMFHacks
Administrator
Hero Member
*****
Offline Offline

Posts: 10987


View Profile
« Reply #11 on: June 02, 2012, 05:32:21 pm »

Find
Code:
WHERE l.id_badge = b.id_badge AND l.ID_MEMBER = $memberID
Change
Code:
WHERE l.id_badge = b.id_badge AND l.ID_MEMBER = $memberID and b.enabled = 1
Logged
shuban
Badge Awards Customer
Full Member
*****
Offline Offline

Posts: 163


View Profile WWW
« Reply #12 on: June 02, 2012, 05:54:55 pm »

Worked, thank you Smiley

Members are really starting to like this!
Logged

SMFHacks
Administrator
Hero Member
*****
Offline Offline

Posts: 10987


View Profile
« Reply #13 on: June 02, 2012, 05:58:12 pm »

No problem. There is a lot you can do exceptionally with custom badges. Kinda makes the forum a mini game and people try to earn them all.
Logged
shuban
Badge Awards Customer
Full Member
*****
Offline Offline

Posts: 163


View Profile WWW
« Reply #14 on: June 02, 2012, 06:00:12 pm »

No problem. There is a lot you can do exceptionally with custom badges. Kinda makes the forum a mini game and people try to earn them all.

People sent me 10's of requests lol
Logged

Pages: [1] 2 Go Up Print 
« previous next »
Jump to:  

Recent
[Today at 07:03:27 am]

[May 16, 2013, 10:13:46 pm]

[May 15, 2013, 11:32:14 pm]

[May 15, 2013, 11:31:24 pm]

[May 12, 2013, 09:10:43 am]

[May 10, 2013, 03:49:55 am]

[May 07, 2013, 07:12:40 pm]

[May 07, 2013, 02:37:14 pm]

[May 06, 2013, 10:29:56 pm]

[May 04, 2013, 03:22:01 pm]
Random Picture
Donate to SMFHacks.com
Help Support the SMFHacks.com mod making.
Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
TinyPortal v0.9.7 © Bloc
SMF and SimpleMachines are registered trademarks of Simple Machines. SMFHacks.com is not affiliated with nor endorsed by Simple Machines.
Page created in 1.293 seconds with 19 queries.