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 11-08-2010, 06:59 AM
FreshFroot's Avatar
FreshFroot FreshFroot is offline
 
Join Date: Jul 2005
Posts: 770
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Username mysql

So I have a small problem. I must be messing up somewhere.

I basically have a few variables, which gather some information from the "search" table.

One of those data variables is the "userid".

Now I stored this userid into a variable. And what I want to do is get the username.

So I am running the following query only to NOT get the username, but a resource code error. I assume I am missing something here.

Code:
 $mrs_user = $mrs_result["userid"]; 

 $the_username = "SELECT username FROM user WHERE userid = " . $mrs_user . "";

$mrs_username = mysql_query($the_username);
Then $mrs_username is called in a search resultbit template.

So what is it, that I am doing wrong here? I'm sure it's something stupid and yet simple.

I get an error of " Resource id #20" for where the username should be placed.

Thanks
Reply With Quote
  #2  
Old 11-08-2010, 10:44 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think the problem is that the return from mysql_query is a resource, and you need to use mysql_result (http://us2.php.net/manual/en/function.mysql-result.php) to get the value.

BTW, is there a reason you're not using the vb database functions (just have to ask )?
Reply With Quote
  #3  
Old 11-08-2010, 04:57 PM
FreshFroot's Avatar
FreshFroot FreshFroot is offline
 
Join Date: Jul 2005
Posts: 770
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
I think the problem is that the return from mysql_query is a resource, and you need to use mysql_result (http://us2.php.net/manual/en/function.mysql-result.php) to get the value.

BTW, is there a reason you're not using the vb database functions (just have to ask )?
I'll have to try that later tonight.

As for the vB database function, which one is that? Are you refering to "$vbulletin->-db" Because if so, I tried that and got the same error.
Reply With Quote
  #4  
Old 11-08-2010, 05:13 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by FreshFroot View Post
As for the vB database function, which one is that? Are you refering to "$vbulletin->-db" Because if so, I tried that and got the same error.
Yeah, that's what I meant. There probably isn't any reason you can't use mysql functions directly, but using vbulletin functions you probably had the same problem for the same reason - you needed to call $db->fetch_array() on your result. But if you know you only want one row you can use $db->query_first and what you get back will be an array with the column names as keys. So your code would be

Code:
$result = $db->query_first($the_username);
$mrs_username = $result['username'];
Reply With Quote
  #5  
Old 11-09-2010, 02:16 AM
FreshFroot's Avatar
FreshFroot FreshFroot is offline
 
Join Date: Jul 2005
Posts: 770
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Amazing seems to work perfectly now.

So the step I was missing was

Code:
$mrs_username = $result['username'];
So I guess my question now is why do we use $result['username]?

Is it because $result is supposed to be an array? And that we can the array of username within $result?
Reply With Quote
  #6  
Old 11-09-2010, 08:07 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by FreshFroot View Post
Is it because $result is supposed to be an array? And that we can the array of username within $result?
Yeah (I think). I guess you can think of what you get back as a database row that's been saved in an array using the column names as the keys, and even if you're only getting one column it's still an array (with one entry).
Reply With Quote
  #7  
Old 11-09-2010, 03:35 PM
FreshFroot's Avatar
FreshFroot FreshFroot is offline
 
Join Date: Jul 2005
Posts: 770
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
Yeah (I think). I guess you can think of what you get back as a database row that's been saved in an array using the column names as the keys, and even if you're only getting one column it's still an array (with one entry).
Wow I totally mis wrote that sentance haha.

I meant pretty much what you said. You would essentially get back rows, but each row of an array would contain multiple data. eg. userid, username and you can choose which to retrive.

Thanks a lot for your help kh99. You helped me learn something new about vB. I'm sure ill be back for something else these days. I have a few small short mods I am going to be working on. But this setup has explained a few things to me about vB.

Thanks
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 03:39 PM.


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.06501 seconds
  • Memory Usage 2,222KB
  • 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
  • (3)bbcode_code
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)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