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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2007
    Posts
    310
    Thanks
    86
    Thanked 3 Times in 3 Posts

    A very silly query question...

    Hello,

    I have a query:

    PHP Code:
    $SQL "SELECT * FROM table WHERE id=".$_GET['id']; 
    But if I add order by to it:

    PHP Code:
    $SQL "SELECT * FROM table WHERE id=".$_GET['id'Order by table_id
    It fails? I know it's something to do with the " being out of place, but surely it has to be there?

    Thank you

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,851
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    PHP Code:
    $SQL "SELECT * FROM table WHERE id='".$_GET['id']."' Order by table_id"
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    stfc_boy (11-10-2007)

  • #3
    Regular Coder
    Join Date
    Oct 2007
    Posts
    277
    Thanks
    2
    Thanked 4 Times in 4 Posts
    a better way to do it I think is this:
    Code:
    $SQL = "SELECT * FROM table WHERE id='$_GET['id']' Order by table_id";

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,018
    Thanks
    2
    Thanked 313 Times in 305 Posts
    That will actually generate a php parse error, because php needs help in figuring out what part of that is the array variable. This will work however -
    PHP Code:
    $SQL "SELECT * FROM table WHERE id='{$_GET['id']}' Order by table_id"
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help 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
    •