I modified " function qa_get_public_from_userids($userids)" to get username & userid information in format of {username}[userid]
here is code :
while ($result=mysql_fetch_assoc($results))
{
$test1 = $result['first_name'];
$test2 = $result['user_id'];
$lastname= $result['last_name'];
$test= '{'.$test1." ".$lastname.'}['.$test2.']';
$useridtopublic[$result['user_id']]=$test;
}
So my result will be "{Shivraj Sawant}[shivrajsa]".
Then I modified function "function qa_get_users_html($userids, $should_include_link, $relative_url_prefix)". I used some string manipulation functions to separate username & userid
Here is my code :
foreach ($userids as $userid) {
$publicusername=$useridtopublic[$userid];
$nametest= strpbrk($publicusername,"[");
$nametest=trim($nametest,"[]");
$test3='['.$nametest.']';
$Pnametest= chop($publicusername,$test3);
$Pnametest=trim($Pnametest,"{}");
$publicusername=$nametest;
$publicusername1=$Pnametest;
$usershtml[$userid]=htmlspecialchars($publicusername1);
if ($should_include_link)
$usershtml[$userid]='<a href="'.qa_path_html('user/'.$publicusername).'" class="qa-user-link">'.$usershtml[$userid].'</a>';
}
return $usershtml;
So "$publicusername1" contains the username(Shivraj Sawant) which will be stroed in "$usershtml" & "$publicusername" contains userid(shivrajsa).
Then I modified "function qa_get_userids_from_public($publicusernames)".
Below is my code :
if (count($publicusernames)) {
$qa_db_connection=qa_db_connection();
$escapedusernames=array();
foreach ($publicusernames as $publicusername)
{
$escapedusernames[]="'".mysql_real_escape_string($publicusername, $qa_db_connection)."'";
}
$results=mysql_query(
'SELECT first_name, user_id FROM user WHERE user_id IN ('.implode(',', $escapedusernames).')',
$qa_db_connection
);
while ($result=mysql_fetch_assoc($results))
{
$publictouserid[$result['first_name']]=$result['user_id'];
}
}
return $publictouserid;
My code is working, correct userid is fetched even if there are many users with same user name.
One thing may be considered that username should not contain "{" or "]" character for given code.
I am not a developement expert, it is just a way I tried & it is working, there could be more optimistic way to do it