Need Help Writing A SQL Query for a Custom Plugin.
-
Okay. I’ve got CometChat and I’m trying to get it to work with buddypress. The developer says it will work just fine with the proper edits to the config.php file so that it can talk to the database properly.
I’d Like to get it working so I can post the config for other Buddypress Users.
I have two sets of things that I need help with – I need to make sure I’m calling the database propery here:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* DATABASE */
include_once dirname(dirname(__FILE__))."/wp-load.php";
define('DB_SERVER', DB_HOST );
define('DB_PORT', '3306' );
define('DB_USERNAME', DB_USER );
define('DB_PASSWORD', '******' );
define('DB_NAME', '**************' );
define('TABLE_PREFIX', $table_prefix_wp );
define('DB_USERTABLE', 'wp_1_useronline' );
define('DB_USERTABLE_NAME', 'displayname' );
define('DB_USERTABLE_USERID', 'userid' );
define('DB_USERTABLE_LASTACTIVITY', 'timestamp' );
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I’m pretty sure that all of the above is correct. As I’m no longer getting database errors. But What I really need help with is the FriendList Functions. These are the default functions in the config.php file:
/* FUNCTIONS */
function getUserID() {
global $current_user;
get_currentuserinfo();
$userid = 0;
if (!empty($current_user->ID)) {
$userid = $current_user->ID;
}
return $userid;
}
function getFriendsList($userid,$time) {
$sql = ("select DISTINCT ".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_USERID." userid,
".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_NAME." username,
".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_LASTACTIVITY." lastactivity,
".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_USERID." avatar, ".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_USERID." link,
cometchat_status.message, cometchat_status.status
from ".TABLE_PREFIX."friends join ".TABLE_PREFIX.DB_USERTABLE."
on ".TABLE_PREFIX."friends.toid = ".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_USERID."
left join cometchat_status on ".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_USERID." = cometchat_status.userid
where ".TABLE_PREFIX."friends.fromid = '".mysql_real_escape_string($userid)."'
order by username asc");
return $sql;
}
function getUserDetails($userid) {
$sql = ("select ".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_USERID." userid, ".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_NAME." username, ".TABLE_PREFIX."useronline.timestamp lastactivity, ".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_USERID." link, ".TABLE_PREFIX.DB_USERTABLE.".user_email avatar, cometchat_status.message, cometchat_status.status from ".TABLE_PREFIX.DB_USERTABLE." left join cometchat_status on ".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_USERID." = cometchat_status.userid left join ".TABLE_PREFIX."useronline on ".TABLE_PREFIX."useronline.userid = ".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_USERID." where ".TABLE_PREFIX.DB_USERTABLE.".".DB_USERTABLE_USERID." = '".mysql_real_escape_string($userid)."'");
return $sql;
}
function updateLastActivity($userid) {
$sql = ("update ".TABLE_PREFIX."useronline set timestamp = '".getTimeStamp()."' where userid = '".mysql_real_escape_string($userid)."'");
return $sql;
}
function getUserStatus($userid) {
$sql = ("select cometchat_status.message, cometchat_status.status from cometchat_status where userid = '".mysql_real_escape_string($userid)."'");
return $sql;
}
function getLink($link) {
return '';
}
function getAvatar($image) {
return"http://www.gravatar.com/avatar/".md5($image)."?d=identicon";
}
function getTimeStamp() {
return current_time('timestamp');
}
function processTime($time) {
return $time;
}
The First Three Function are the most important to get right and I don’t really know how to edit them so they will pull the right information from the right tables.
function getUserID()
function getFriendsList($userid,$time)
&
function getUserDetails($userid)
The instructions for modifying these functions is located here:
http://www.cometchat.com/support/page/documentation?record=16
But being rather new to SQL queries within PHP – the instructions don’t make much sense to me.
Thanks in advance for your help
- The topic ‘Need Help Writing A SQL Query for a Custom Plugin.’ is closed to new replies.