The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
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); 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 |
#2
|
|||
|
|||
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 )? |
#3
|
||||
|
||||
Quote:
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. |
#4
|
|||
|
|||
Quote:
Code:
$result = $db->query_first($the_username); $mrs_username = $result['username']; |
#5
|
||||
|
||||
Amazing seems to work perfectly now.
So the step I was missing was Code:
$mrs_username = $result['username']; Is it because $result is supposed to be an array? And that we can the array of username within $result? |
#6
|
|||
|
|||
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).
|
#7
|
||||
|
||||
Quote:
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 |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|