PDA

View Full Version : Trying to change some friends list code.


LCN2007
10-16-2009, 02:39 PM
Im trying to modify some code, im hoping someone can help me.

I have this chunk of code that is set to populate a friends list with all (offline/online) members that are on your vbulletin friends list, but i would like to have it set to populate only online friends from can anyone help.



function getFriendsList($userid,$time) {
$sql = ("select ".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, friends_status.message, friends_status.status from ".TABLE_PREFIX."userlist join ".TABLE_PREFIX."user on ".TABLE_PREFIX."userlist.relationid = ".TABLE_PREFIX."user.userid left join friends_status on ".TABLE_PREFIX.DB_USERTABLE.".userid = friends_status.userid where ".TABLE_PREFIX."userlist.friend = 'yes' and ".TABLE_PREFIX."userlist.userid = '".mysql_real_escape_string($userid)."' order by username asc");
return $sql;
}

Lynne
10-16-2009, 02:58 PM
And what are you getting as a result of that code? You didn't tell us what was wrong.



Also, I have watch Sir Adrian write queries many times before and one thing I have learned from watching him is that seeing what is wrong with your query is sooooo much easier if you write it out using multiple lines:
$sql = ("select ".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, friends_status.message, friends_status.status
from ".TABLE_PREFIX."userlist
join ".TABLE_PREFIX."user on ".TABLE_PREFIX."userlist.relationid = ".TABLE_PREFIX."user.userid
left join friends_status on ".TABLE_PREFIX.DB_USERTABLE.".userid = friends_status.userid
where ".TABLE_PREFIX."userlist.friend = 'yes' and ".TABLE_PREFIX."userlist.userid = '".mysql_real_escape_string($userid)."'
order by username asc");


He also indents and always capitilizes actions - I didn't do that to yours, but I always do that to mine now. It just makes it much easier to read.

I'm not a query person, so I'm not gonna tear it apart to see what is wrong (especially since you never said what was wrong with it), but I did see that youare calling the avatar field from the user table and there is no avatar field in the user table.

LCN2007
10-16-2009, 03:17 PM
Nothing is wrong per say i did state what i was looking for help with though.

the code i posted above queries the vb friends list and populates it on a list, this includes on and off line users. If if the user is online a little button or light turns on satting that they are online.

I would like to modify the code to show only online users that are on my friends list.

Sorry i cannot post a picture of the problem because there is not one, im just looking for help to change the code i have.

--------------- Added 1255787424 at 1255787424 ---------------

Does anyone know how to make this query?

LCN2007
10-19-2009, 01:37 PM
No one?

Thanks