Forum Moderators: coopster

Message Too Old, No Replies

secleting from a data base and ordering by views

         

level9

7:53 pm on Mar 10, 2006 (gmt 0)

10+ Year Member



Hi everyone, I have a simple problem that is bugging me. When getting data from a database I’m ordering them by the times it has been viewed descending, but the problem I am having is it is only selecting by the first number

EXP.
Its ordering something like this
7, 4, 4, 2, 14, 12, 10

When I’m wanting it to be like..
14, 12, 10, 7, 4, 4, 2

You get the idea.. But as I said it’s selecting by the first number only. Here is the select code I am using..


<?php
mysql_select_db($DB, $review);
$query_Recordset1 = "SELECT * FROM reviews WHERE activeYN = 1 ORDER BY `id` DESC LIMIT 10";
$Recordset1 = mysql_query($query_Recordset1, $review) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>

Any ideas on how to fix the problem I am having?

nfs2

7:56 pm on Mar 10, 2006 (gmt 0)

10+ Year Member



Change DESC to ASC

level9

7:58 pm on Mar 10, 2006 (gmt 0)

10+ Year Member



i tried that but it still is only selecting by the first number

coopster

9:59 pm on Mar 10, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, level9.

You don't seem to be processing the result set here. Picture the result set coming back as a big spreadsheet of data, columns and rows. You are only reading the first row.

There is a page in our PHP Forum Library [webmasterworld.com] that describes the Basics of extracting data from MySQL [webmasterworld.com] that may help you over the hump.

inveni0

10:40 pm on Mar 10, 2006 (gmt 0)

10+ Year Member



Actually, you're having a problem similar to one I had recently. Is the 'ID' column set up as "INT" type, or VARCHAR? I changed mine to INT and that fixed the sorting problem.

My code is essentially just like yours. That's why I think our problems are related.

level9

11:28 pm on Mar 10, 2006 (gmt 0)

10+ Year Member



currently it's VARCHAR im going to try INT and see what i get

level9

11:31 pm on Mar 10, 2006 (gmt 0)

10+ Year Member



changing to INT worked, thanks for the help everyone