/    Sign up×
Community /Pin to ProfileBookmark

What am I doing wrong ?

Hi I am having problems with the folloing statment:

[CODE]
$Exist = “SELECT CAST(Score AS UNSIGNED) AS loopies FROM playerstats WHERE id_Player=’16’ AND loopies > ’49′”;
[/CODE]

I keep getting the error that “loopies” is a unknown column. But when I run the statment in my DB admin software the column has been created.

What am I doing wrong and what do I do to correct it?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 17.2007 — You're using "loopies" as an alias for the CAST() of the Score column, but that casting won't be done until [i]after[/i] the WHERE clause has identified an applicable row; so that means that while the WHERE clause is processing there is not yet a "loopies" value. So if the casting is necessary to do the ">" comparison, you'll need to use the same CAST() call in the WHERE clause:
[code=php]
$Exist = "SELECT CAST(Score AS UNSIGNED) AS loopies FROM playerstats WHERE id_Player='16' AND CAST(Score AS UNSIGNED) > '49'";
[/code]
Copy linkTweet thisAlerts:
@gogelpotauthorMar 17.2007 — Thanks. :o

That was real stupid of me.
Copy linkTweet thisAlerts:
@NightShift58Mar 17.2007 — The alternative - to avoid double CASTing - is to use HAVING:[code=php]
$Exist = "
SELECT CAST(Score AS UNSIGNED) AS loopies
FROM playerstats
HAVING id_Player='16'
AND loopies > 49
";[/code]
×

Success!

Help @gogelpot 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.28,
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,
)...