/    Sign up×
Community /Pin to ProfileBookmark

sql sort by votes

hello everyone !!!
i wanna sort top 10 website by votes but i m having this problem
suppose sql =


____________________________

title vote
webdevelpor 333
coding fourm 312
boards 20 77


_________________________

and i m using this php codes but problem is 77 is coming at top then 333 and then 312 ..

php codes

[code=php]
/// connection file /////
$rs = mysql_query (“SELECT *
FROM `site`
ORDER BY `vote` DESC
LIMIT 0 , 10”);
while ($row= mysql_fetch_array($rs))
{
$title = $row[‘title’];
$vote = $row[‘vote’];
echo “<table bgcolor=’#FFC088′ width=’600′ cellspacing=’4′ cellpadding=’4′>
<tr><td><b>$title</a></a></td>
<td width=20> $vote</td></tr></table>”;
}
}

[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 13.2006 — By any chance is vote not a numeric type of column, perhaps a varchar type? If so, then it's sorting the numbers as strings, not as numeric values. The fix would be to change the vote column to an integer type.
Copy linkTweet thisAlerts:
@fsagharauthorJan 13.2006 — i changed it to INT and now it's working fine thanks for reply
×

Success!

Help @fsaghar 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.21,
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,
)...