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 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2010
    Posts
    37
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Raging on this sql error

    Cant find a reason for this not to work

    Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM urls ORDER BY id DESC LIMIT 0,10' at line 1


    PHP Code:
    <?php
    $con 
    mysql_connect("localhost","***","***");
    mysql_select_db("dubstep3_project1");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }
    mysql_query("DELETE * FROM urls ORDER BY id DESC LIMIT 0,10"
    or die(
    mysql_error()); 
    ?>
    Any help is greatly appreciated


    Also in-cases its not obvious enough trying to delete top 10 row...i tried the TOP function and that also does not work.

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    Not sure about the "ORDER BY id DESC LIMIT 0,10" bit, but you definitely don't need the * there in the sql. You're not selecting anything or updating one single item - you're deleting a whole row so mysql doesn't expect you to tell it what to delete.

    Remove the * and see what happens.

    If that doesn't work, you'll need to select 10 records using the "ORDER BY id DESC LIMIT 0,10" and then delete them.
    I can't really think of anything to write here now...

  • #3
    New Coder
    Join Date
    Oct 2010
    Posts
    37
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Okay, removing the * gave me this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '10' at line 1.


    How would I go about deleting the rows after i select them??

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    LIMIT is the literal number to delete. Its impossible to delete a range of 0 to 10. Just use 10.
    Here's a link to the delete syntax as well: http://dev.mysql.com/doc/refman/5.0/en/delete.html

  • Users who have thanked Fou-Lu for this post:

    fus10n (04-08-2012)

  • #5
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    Quote Originally Posted by fus10n View Post
    How would I go about deleting the rows after i select them??
    Just to clarify something, you're not selecting any rows when using the delete command. You're simply telling it to delete things based on a condition. There is no selection involved.
    I can't really think of anything to write here now...


  •  

    Posting Permissions

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