/    Sign up×
Community /Pin to ProfileBookmark

Help with large mysql query

Ok Im trying to do a small modification to a query but no matter what I try it doenst work so id like some help. Im working on a modifcation for an open source forum system I work with

[code=php]
$sql = “SELECT t.ID, t.sticky, t.status, t.viewcount, t.postcount, t.oldboardid, ”
.” fp.subject, fp.authorid, fp.pollid,fp.body, LENGTH(fp.body) AS postlength, ”
.” fp.authorid as firstpostuserid, ”
.” ufp.displayname as firstpostusername, ”
.” ufp.displayformat as firstpostusernameformat, ”
.” fp.postdate AS firstpostdate, ”
.” lp.ID AS lastpostid, ”
.” lp.authorid AS lastpostuserid, ”
.” ulp.displayname as lastpostusername, ”
.” ulp.displayformat as lastpostusernameformat, ”
.” lp.postdate AS lastpostdate”
.” FROM “.TABLE_THREADS.” t, “.TABLE_USERS.” ufp, “.TABLE_USERS.” ulp, “.TABLE_POSTS.” fp, “.TABLE_POSTS.” lp ”
.” WHERE fp.ID = t.postidfirst ”
.” AND lp.ID = t.postidlast ”
.” AND ufp.ID = fp.authorid ”
.” AND ulp.ID = lp.authorid ”
.” AND t.boardid = $boardid ”
.” ORDER BY sticky DESC, lastpostdate DESC”
.” LIMIT “.intval($startrow).”, “.intval($configoptions[perpagethreads]);
[/code]

Heres my problem

I would like to change this line

[code=php]
.” AND t.boardid = $boardid “[/code]

so that it will select it if t.boardid=$boardid [b]OR[/b] t.sticky=2 but whenever i put an or clause in like this

[code=php]
.” AND t.boardid = $boardid ”
.” OR t.sticky= 2 ”
[/code]

I get this error returned

[b]Got error 28 from table handler[/b]

thank you for any help you can offer

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@BuezaWebDevAug 18.2004 — Here you go:

[code=php]


." (AND t.boardid = $boardid OR t.sticky = 2) "

[/code]
Copy linkTweet thisAlerts:
@ConorauthorAug 18.2004 — hmm, I tried that and recieved this error

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '(AND t.boardid = 1 OR t.sticky = 2) ORDER BY sticky DESC, last
Copy linkTweet thisAlerts:
@NogDogAug 18.2004 — How about:
[code=php]." AND (t.boardid = $boardid OR t.sticky = 2) "[/code]
Copy linkTweet thisAlerts:
@ConorauthorAug 18.2004 — thank you that worked.
×

Success!

Help @Conor 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.17,
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,
)...