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,973
  • Latest: NonStop
Stats
  • Total Posts: 196,234
  • Total Topics: 21,353
  • Online today: 739
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 279
  • Total: 279

DKP Check for the currently logged in user

Started by sloanja, March 21, 2007, 03:43:54 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

sloanja

I don't know if this is the right place for this, but I coded the following inspired from the 'Your DKP' Joomla block.  I recently tore down Joomla, but wanted to keep the block.  I had to do a complete recode, but the following works on my installation.

This assumes that EQDKP is in the same database as your SMF/TP forums.  It also assumes that the currently logged on user's logon name is the same as their character's name that appears on the DKP Boards.  For example, Tigertamp is a username and Tigertamp is a character on the EQDKP board.


Put the following in a phpbox:

global $db_prefix, $context, $user_info, $ID_MEMBER;

$EQPrefix = "eqdkp_";


echo '<center>';
$sql1 = "SELECT * FROM {$EQPrefix}members WHERE member_name='" . $context['user']['name'] ."'";

if ($context['user']['is_logged']){
$request = db_query($sql1, __FILE__, __LINE__);


$row = mysql_fetch_assoc($request);

if (empty($row['member_name'])){

echo 'You have no DKP. Join a run!<br>';

}
else
{

$totaldkp=$row['member_earned'] - $row['member_spent'] + $row['member_adjustment'];
echo 'You have '. $totaldkp .' DKP points. <br>';

}

};

if (!$context['user']['is_logged']){
echo 'Please login or register to see your DKP.';
}

echo '</center>';

Hakker

would love to see a version that has the database not in the TP one

maviel

anyone know how to call another database on the server using this code?

Ianedres

You would have to implement the mysql_connect and mysql_select_db functions ahead of the queries...  that would allow the code to connect to another server (outside of TP) and then use the database tables for EverQuest.

Provided the table structure was the same, the rest of the code would work from there and the code should be able to access the information.

I don't have EQ, but this is the general scope of what would be needed.

maviel

#4
ok, i am new to php and i checked php.net... code as u described would look like this?


mysql_connect (DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db (DB_NAME);


and direct after put the code:


global $db_prefix, $context, $user_info, $ID_MEMBER;

$EQPrefix = "eqdkp_";


echo '<center>';
$sql1 = "SELECT * FROM {$EQPrefix}members WHERE member_name='" . $context['user']['name'] ."'";

if ($context['user']['is_logged']){
$request = db_query($sql1, __FILE__, __LINE__);


$row = mysql_fetch_assoc($request);

if (empty($row['member_name'])){

echo 'You have no DKP. Join a run!<br>';

}
else
{

$totaldkp=$row['member_earned'] - $row['member_spent'] + $row['member_adjustment'];
echo 'You have '. $totaldkp .' DKP points. <br>';

}

};

if (!$context['user']['is_logged']){
echo 'Please login or register to see your DKP.';
}

echo '</center>';


EDIT: it now reads from my 2nd database which means that the site thinks it is on my "portal" database. Anyone know how to fix so i can make this code call back to the other database in the end of the 2nd code.

Ianedres

You could put those two functions at the top of the script; you will need to replace the constants (in all-caps) with your site's info for the host, user name to access the server, and accompanying password for the mysql_connect.

Then replace the DB_NAME with your EQ database that is storing your info.

A simple change of db_query (SMF's version) to a standard mysql_query call is needed; I also added LIMIT 1 at the end of the query to restrict its results to just one.

Try this...  may need refining, but should be close...
global $db_prefix, $context, $user_info, $ID_MEMBER;

$EQPrefix = "eqdkp_";

$db_host = 'your mysql host name';
$db_user = 'your database user name';
$db_pass = 'your database password';
$db_table = 'database name to access';

// edit variables above to your site's requirements

mysql_connect ($db_host, $db_user, $db_pass);
mysql_select_db ($db_table);

echo '<center>';
$sql1 = "SELECT * FROM {$EQPrefix}members WHERE member_name='" . $context['user']['name'] ."' LIMIT 1";

if ($context['user']['is_logged']){
$request = mysql_query($sql1);

$row = mysql_fetch_assoc($request);

if (empty($row['member_name'])){

echo 'You have no DKP. Join a run!<br>';

}
else
{

$totaldkp=$row['member_earned'] - $row['member_spent'] + $row['member_adjustment'];
echo 'You have '. $totaldkp .' DKP points. <br>';

}

};

if (!$context['user']['is_logged']){
echo 'Please login or register to see your DKP.';
}

echo '</center>';

maviel

this did not work at all i did get a blank page when putting this code into my block however my code worked but direct after the rest of the page wanted to read from my "_dkp" database instead of my "_portal" database.

Ianedres

Without actual access to the database (which I am not asking for) and/or knowing the table's structure, it will be difficult to make it work sight-unseen.

This was a quick attempt to demonstrate what would be needed to change over to another database table.

maviel

Database Error: Table '****_udkp.smf_messages' doesn't exist ... is the message i get were i have the news of the page...

the code i am using now is the same as yours i forgot to put the direct name of the database... my other database were i have my portal is on ****_portal.smf_messages' i guess.

Ianedres

Most likely, you will need to add code at the end of this script to change back to the SMF database so it can find the tables for SMF since the block returns control back to SMF. It would very similar to the top of the script with your SMF information.


This website is proudly hosted on Crocweb Cloud Website Hosting.