Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-07-2012, 08:17 PM   PM User | #1
fus10n
New Coder

 
Join Date: Oct 2010
Posts: 37
Thanks: 3
Thanked 0 Times in 0 Posts
fus10n is an unknown quantity at this point
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.
fus10n is offline   Reply With Quote
Old 04-07-2012, 08:27 PM   PM User | #2
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,521
Thanks: 45
Thanked 440 Times in 429 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 04-07-2012, 08:30 PM   PM User | #3
fus10n
New Coder

 
Join Date: Oct 2010
Posts: 37
Thanks: 3
Thanked 0 Times in 0 Posts
fus10n is an unknown quantity at this point
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??
fus10n is offline   Reply With Quote
Old 04-07-2012, 08:40 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
fus10n (04-07-2012)
Old 04-08-2012, 12:40 AM   PM User | #5
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,521
Thanks: 45
Thanked 440 Times in 429 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:18 AM.


Advertisement
Log in to turn off these ads.