Jump to content


Photo

Ordering Question


  • Please log in to reply
5 replies to this topic

#1 aconnal

aconnal
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 22 September 2006 - 09:06 AM

Hi, I'm new to the board so please be gentle with me.

Anyway I seem to have a problem, I am creating a league table for sales people, I have got it doing everything I want apart from one thing, the ordering.

My script creates a temporary table and then I extract the information from that table and order it by the total of sales, however the ordering is wrong this is how it is ordering the total of sales at the moment:

9675
2140
18790??

Surely the 18790 should be at the top? It looks like mysql is ordering the numbers by the first number and not the whole value!!

Any thoughts on this would be appriciated.

Thanks

A

#2 steveclondon

steveclondon
  • Members
  • PipPipPip
  • Advanced Member
  • 161 posts

Posted 22 September 2006 - 09:27 AM

would need to see the table sql (or at least that column) to know and the sql code your are using to retreave the information.

#3 aconnal

aconnal
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 22 September 2006 - 09:35 AM

Cool, here is the code to create the temporary table:

$CREATE = "CREATE TEMPORARY TABLE temp_total_sales(total_sale_id int(10) NOT NULL AUTO_INCREMENT, salesperson_id int(10) NOT NULL, total_sales char(50) NOT NULL, PRIMARY KEY(total_sale_id))";

mysql_query($CREATE) or die(mysql_error());

Here is the query to extract the information:

$QUERY3 = "SELECT * FROM temp_total_sales ORDER BY total_sales DESC";
$RESULT3 = mysql_query($QUERY3) or die(mysql_error());
$NUMRESULTS3 = mysql_numrows($RESULT3);

Hope this helps.

Cheers

A

#4 steveclondon

steveclondon
  • Members
  • PipPipPip
  • Advanced Member
  • 161 posts

Posted 22 September 2006 - 09:39 AM

I would make total sales in the table an int or a float before going any further.

#5 steveclondon

steveclondon
  • Members
  • PipPipPip
  • Advanced Member
  • 161 posts

Posted 22 September 2006 - 09:41 AM

or decimal which is best (6,2) .

#6 aconnal

aconnal
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 22 September 2006 - 09:44 AM

Ah how dim am I yes I've changed it to an int and it works fine now.

Thanks for that.

A




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users