View Full Version : Display username (not your own) on non-vb pages
Digma
09-24-2009, 10:11 AM
Is there a way of showing a username other than your own on a non-vb page, while working with separate databases but within the same domain?
I've already got the userid stored in the other database under author id and would like to be able to show the username belonging to that when the entry is requested on the site.
Say someone has submitted a guide and he has userid 5,000. When he submits his content the userid is stored in the content database. Now when someone else tries to access the page where that specific content is on, I would like the author id to be linked to his username in the vbulletin database.
I've been trying to experiment using global.php, but either got my own username or Unregistered Users (when logged out from the system).
Can anyone give me a lead where to look further (already checked [How-To] vBulletin API Basics: Creating Custom Pages & Misc. but couldn't find the answer there).
Thank you in advance.
--------------- Added 1253790760 at 1253790760 ---------------
Hmmm, I think this should have gone into 'Programming Discussion'. Sorry for the wrong placement.
Lynne
09-24-2009, 03:06 PM
So basically, you have two user tables - one for where they submit guides and the other on vbulletin and you want to be able to link the two by userid? You should be able to do this - including global.php (or init.php) should allow you to connect to the vbulletin database. It's hard to know where you went wrong without seeing your code.
Digma
09-24-2009, 07:18 PM
Thank you for responding to my thread Lynne, much appreciated and my apologies for not being thorough enough on the information given. Basically my situation is as followed:
I am currently working with 2 databases:
1. The forum database is where all the vbulletin information resides.
2. The site database is where all the site (so non-vb) information resides.
Mind that I have been fiddling around with the code to see what works. In an earlier part of the code below I have already included global.php and also have a login system that shows the person logged in.
However in relation to the code below I changed the author_id in the SITE database to reflect another user. When loading the code it still shows my username, not the one it should really relate to. Also when I logout I get to see Unregistered.
The last couple of line is what is currently troubling me to solve. Perhaps I am missing something stupidely simple and I just need to be pointed into the right direction or there is simply something fundamentally wrong with those few lines.
<?
$query="select b.id, b.publicationdate, b.title, b.shortdesc, b.cat_id, b.author_id, c.naam from si_news b, si_news_cat c where b.publicationdate <= now() and c.id = b.cat_id order by b.publicationdate desc limit 0,10";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
{
$row[publicationdate]=change_date($row[publicationdate]);
echo "<P><H1>".$row['title']."</H1>";
echo "<H3>".$row[publicationdate]."</H3>";
echo $row['shortdesc']." <a href=\"blabla.com\">Read More</a><br>";
echo "<H2>Category: ".$row['naam'];
$row['author_id']=$vbulletin->userinfo['userid'];
echo " Author: ".$vbulletin->userinfo['username']."</H2></P>";
}
?>
Note: I am not a real coder, so it might not be up to the standard of info you're used to. If you need more just let me know.
Thank you in advance.
Lynne
09-24-2009, 08:53 PM
What you did right here:
$row['author_id']=$vbulletin->userinfo['userid'];
echo " Author: ".$vbulletin->userinfo['username']."</H2></P>";
You just set $row['author_id'] to *your* userid. Why? And then you spit out your username. I thought you wanted to use the userid from the query and get the username associated with it from the vbulletin database?
You need to do a quick query to the vbulletin user table to grab the username associated with the userid of $row['author_id']. I think you can do a JOIN in your original query for it, but I'm not sure of the exact syntax with it being to another database.
charlie71
09-26-2009, 03:39 PM
You can use something like this for getting the username by a userid:
$username = mysql_result($db->query_read("select username from " . TABLE_PREFIX . "user where userid = '$userid' order by userid desc limit 1"), 0);
Don't forget to escape $userid properly by using the vbulletin escape functions...
Digma
09-30-2009, 08:05 AM
Thanks for the information. I'll dive into it and see if I can come up with something properly working going from both your information. Again, thanks!
--------------- Added 1254303795 at 1254303795 ---------------
Problem solved I came up with the following query and it works:
$query="select b.id, b.publicationdate, b.title, b.shortdesc, b.cat_id, b.author_id, c.naam, d.username from si_news_cat c, si_news b INNER JOIN forums.fo_user d ON d.userid=b.author_id where b.publicationdate <= now() and c.id = b.cat_id order by b.publicationdate desc limit 0,10";
Thanks again for the pointers.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.