/    Sign up×
Community /Pin to ProfileBookmark

Database or buggy PHP?

Okay, so I’m using a simple SELECT FROM query to get a name, should be simple, right?

[code=php]
$author=mysql_query(“SELECT username FROM users WHERE id=’$aid'”);
echo($author);
[/code]

Yes, $aid is set. Now, I’ve run this same tibit of code in phpMyAdmin, and it works, but in my script I get this:

[QUOTE]

Resource id #6Resource id #7Resource id #8Resource id #9Resource id #10Resource id #11Resource id #12Resource id #13Resource id #14Resource id #15Resource id #16Resource id #17Resource id #18Resource id #19Resource id #20Resource id #21

[/QUOTE]

I don’t even understand that, let alone know what it means… can anyone help me here? I want $author to have the username.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@solavarMay 09.2004 — Yes, the way you've got it, $author is indeed the resource id, and not the 'author' you are looking for.

Here is how it should be:

[code=php]
$result=mysql_query("SELECT username FROM users WHERE id='$aid'");

$authors = mysql_fetch_row($result);
$author = $authors[0];
echo $author;

[/code]
Copy linkTweet thisAlerts:
@MstrBobauthorMay 09.2004 — Thank you ever so kindly, it works like a charm! This is why I love these forums...
×

Success!

Help @MstrBob spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...