Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts

    View the report in ascending order

    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:

    PHP Code:
     $query "SELECT plt_no FROM plt_transact WHERE plt_date BETWEEN '" $_POST["from_date"] . "' AND '" $_POST["to_date"] . "' "
    I try this code
    PHP 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
    Last edited by newphpcoder; 11-25-2010 at 12:58 AM.

  • #2
    New Coder
    Join Date
    Nov 2010
    Posts
    12
    Thanks
    0
    Thanked 1 Time in 1 Post
    Try:

    PHP Code:
    $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:

    PHP Code:
    $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
    Last edited by WA; 11-25-2010 at 04:57 AM.

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jim_keller View Post
    Try:

    PHP Code:
    $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:

    PHP Code:
    $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

  • #4
    New Coder
    Join Date
    Nov 2010
    Posts
    12
    Thanks
    0
    Thanked 1 Time in 1 Post
    Which field do you want it to be sorted by?

    -Jim
    Last edited by WA; 11-25-2010 at 04:56 AM.

  • #5
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    4
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by jim_keller View Post
    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.
    Last edited by ac04; 11-25-2010 at 01:20 AM.

  • #6
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jim_keller View Post
    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
    the plt_no

  • #7
    New Coder
    Join Date
    Nov 2010
    Posts
    12
    Thanks
    0
    Thanked 1 Time in 1 Post
    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?

  • #8
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jim_keller View Post
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •