...

View Full Version : View the report in ascending order



newphpcoder
11-25-2010, 01:48 AM
Good day!

I have a mysql_query code to sleect the date from the database and my problem is the output is not in ascending order. Here is my code:



$query = "SELECT plt_no FROM plt_transact WHERE plt_date BETWEEN '" . $_POST["from_date"] . "' AND '" . $_POST["to_date"] . "' ";


I try this code


$query = "SELECT plt_no FROM plt_transact WHERE plt_date BETWEEN '" . $_POST["from_date"] . "' AND '" . $_POST["to_date"] . "' ORDER BY plt_no ASC ";


But it did not work...where i can put the code for Asc.

Thank you

jim_keller
11-25-2010, 01:54 AM
Try:


$query = "SELECT plt_no FROM plt_transact WHERE plt_date BETWEEN '" . $_POST["from_date"] . "' AND '" . $_POST["to_date"] . "' ORDER BY plt_date ASC ";

However, you should never pass $_POST data directly to a query because it leaves you open to SQL injection attacks. The following would be better:



$from_date = mysql_real_escape_string($_POST['from_date']);
$to_date = mysql_real_escape_string($_POST['to_date']);

$query = "SELECT plt_no FROM plt_transact WHERE plt_date BETWEEN '{$from_date}' AND '{$to_date}' ORDER BY plt_date ASC ";



- Jim Keller

newphpcoder
11-25-2010, 02:01 AM
Try:


$query = "SELECT plt_no FROM plt_transact WHERE plt_date BETWEEN '" . $_POST["from_date"] . "' AND '" . $_POST["to_date"] . "' ORDER BY plt_date ASC ";

However, you should never pass $_POST data directly to a query because it leaves you open to SQL injection attacks. The following would be better:



$from_date = mysql_real_escape_string($_POST['from_date']);
$to_date = mysql_real_escape_string($_POST['to_date']);

$query = "SELECT plt_no FROM plt_transact WHERE plt_date BETWEEN '{$from_date}' AND '{$to_date}' ORDER BY plt_date ASC ";



- Jim Keller
http://lamplighterphp.org . The better way to develop in PHP.

I try the code you suggested but nothing change

jim_keller
11-25-2010, 02:08 AM
Which field do you want it to be sorted by?

-Jim

ac04
11-25-2010, 02:14 AM
Which field do you want it to be sorted by?


http://www.codingforums.com/showthread.php?t=210234
That's the other thread that he made about this.

According to that, he wants it ordered by the number, not the date.

Without seeing an example of what's actually wrong, it's very difficult to help.

Simply changing plt_date ASC to plt_no ASC should hopefully do it, in the example code that you gave him.

newphpcoder
11-25-2010, 02:19 AM
Which field do you want it to be sorted by?

-Jim

http://lamplighterphp.org - The better way to develop in PHP
Context - Philadelphia web design and development (http://contextllc.com)

the plt_no

jim_keller
11-25-2010, 02:21 AM
your original code will order by plt_no - are you sure you're not getting confused by the fact that plt_no may not be in order if certain rows are omitted because they don't fall within the search date range?

newphpcoder
11-25-2010, 02:32 AM
your original code will order by plt_no - are you sure you're not getting confused by the fact that plt_no may not be in order if certain rows are omitted because they don't fall within the search date range?

It is ok that depend on the date.Thank you



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum