/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] php sql query doesnt work?

Hi ive got this code, which is the top half section of the query.
once i add “order” and “AND ORDER BY order DESC” it doesnt work.
would anyone help me out and say why that wouldnt work. thanks

my plan was to make it so the user comments are the newer posts at the top.

[code=php]
$query2 = “SELECT order, id, poster, subject, message FROM messages WHERE id = ‘$id’ AND ORDER BY order DESC”;
$sqlinbox2= mysql_query($query2);

if (!mysql_num_rows($sqlinbox2) ){

?>
<center><p><b>No comments to display</b></p></center>
<?

}else{

$num2 = ‘1’;
while($inbox2 = mysql_fetch_array($sqlinbox2))
{
[/code]

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@TheBearMayNov 29.2008 — Maybe "Order by [b]$[/b]order" instead of "Order by order"? Also may need to change the column "order" to messages.order to keep it from being interpreted as an SQL reserved word
Copy linkTweet thisAlerts:
@mitchellauthorNov 29.2008 — cheers man but it still says an error
Copy linkTweet thisAlerts:
@TheBearMayNov 29.2008 — What's the error message - May need to use: mysql_error()
Copy linkTweet thisAlerts:
@mitchellauthorNov 29.2008 — it says:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource[/QUOTE]
Copy linkTweet thisAlerts:
@NogDogNov 29.2008 — There should not be an "AND" between the WHERE and ORDER BY clauses.
Copy linkTweet thisAlerts:
@mitchellauthorNov 30.2008 — Thanks NogDog but the error still comes up
Copy linkTweet thisAlerts:
@mitchellauthorNov 30.2008 — is this a valid query

$query2 = "SELECT message_order, id, poster, subject, message FROM messages WHERE id = '$id' ORDER BY message_order DESC";
[/QUOTE]
Copy linkTweet thisAlerts:
@chazzyNov 30.2008 — is this a valid query[/QUOTE]

Looks like it, but to validate you should print out the value of $query somewhere and post it here (after the variables have been applied)
Copy linkTweet thisAlerts:
@mitchellauthorNov 30.2008 — Wow, its working now, i really dont understand why it works now?

Thanks for your replys
Copy linkTweet thisAlerts:
@scragarNov 30.2008 — mysql is incase sensitive, order is a key word, I'm guessing MYSQL doesn't like you throwing them about when it's not expecting them.
SELECT <span><code>order</code></span>, <span><code>id</code></span>, <span><code>poster</code></span>, <span><code>subject</code></span>, <span><code>message</code></span> FROM <span><code>messages</code></span> WHERE id = '$id' ORDER BY <span><code>order</code></span> DESC
×

Success!

Help @mitchell 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.5,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...