Hey Guys! :)

Sorry to bother you all I can't seem to get my code to work and I would be much obliged if you could help me out.

So what I was trying to do was get a column from a table of my database and show only the top 'points' e.g. 8, although the code works i've also group and order by points DESC so it shows highest first and goes lower e.g.

Username - 90
Username2 - 80

All looks good! BUT its showing like

Username3 - 3
Username4 - 18
Username5 - 1

So I have recognized it is only going by the first digit as its not putting say 18 above the 3 like it should. I would really love help on this as I am stumped on what to do.

Recommended Answers

All 3 Replies

What data type you have specified for your points field in your database..
post your table structure and your query...

Okay my database table is:

`id` int(11) NOT NULL auto_increment
`username` varchar(30) NOT NULL default ''
`active` varchar(10) NOT NULL default '0'

id is the tables primary key, username is the name of the user who has X active points in the query and as I am sure you have gathered the active column is the points that are being used to order by DESC.

PHP output query is:

<?
$query = mysql_query("SELECT *
FROM `users` ORDER BY `active` DESC LIMIT 8");
while($result = mysql_fetch_array($query)){
?>
<td><? echo"$result[username]"; ?></td><td><? echo"$result[active]"; ?></td>
<?
}
?>

That sort of thing but its not turning out like it should. My current output is:

User1 85
User2 8
User3 5
User4 3
User5 18
User6 1
User7 1
User8 1

make active column as integer data type in your data base table structure, then you will be sure getting correct result.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.