Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 09-24-2009, 10:11 AM
Digma Digma is offline
 
Join Date: Nov 2004
Location: Netherlands
Posts: 60
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Display username (not your own) on non-vb pages

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 [DATE]1253790760[/DATE] at [TIME]1253790760[/TIME] ---------------

Hmmm, I think this should have gone into 'Programming Discussion'. Sorry for the wrong placement.
Reply With Quote
  #2  
Old 09-24-2009, 03:06 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 09-24-2009, 07:18 PM
Digma Digma is offline
 
Join Date: Nov 2004
Location: Netherlands
Posts: 60
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.

PHP Code:
       <?

            $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.
Reply With Quote
  #4  
Old 09-24-2009, 08:53 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What you did right here:
PHP Code:
            $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.
Reply With Quote
  #5  
Old 09-26-2009, 03:39 PM
charlie71 charlie71 is offline
 
Join Date: Sep 2008
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You can use something like this for getting the username by a userid:

Code:
$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...
Reply With Quote
  #6  
Old 09-30-2009, 08:05 AM
Digma Digma is offline
 
Join Date: Nov 2004
Location: Netherlands
Posts: 60
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 [DATE]1254303795[/DATE] at [TIME]1254303795[/TIME] ---------------

Problem solved I came up with the following query and it works:
PHP Code:
$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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:41 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04311 seconds
  • Memory Usage 2,219KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete