Jump to content


Photo

Update help


  • Please log in to reply
4 replies to this topic

#1 Woodie

Woodie
  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 09 September 2003 - 01:09 AM

need a little guidance if anyone can help!

I want to update just a selection of rows based on some information given to the query.

My update statement reads as follows....

UPDATE table SET fieldx = fieldx+1 WHERE fieldx = \'$value\' ORDER BY fielda DESC LIMIT 4;

now this is done in a php script that generates $value from another query to the same table before this update query is attempted!

that query is as follows..

SELECT * FROM table WHERE filedy = \'$val\' ORDER BY fielda DESC;

and $val is user defined an not null!

I am using php 4.0 (on the server I use but I have no admin priviledges!)

is there something I\'m missing with the LIMIT statement?

#2 PHPcadet

PHPcadet
  • Members
  • PipPip
  • Member
  • 14 posts
  • LocationPlant City, Florida

Posted 09 September 2003 - 01:36 AM

The words \"table\" and \"tables\" are reserved words in MySQL. Not sure if that\'s your problem.
If builders built buildings the way programmers write programs, then the first termite to come along would destroy civilization -- Anonymous

#3 Woodie

Woodie
  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 09 September 2003 - 01:20 PM

The tables are not actually called that. Sorry I did not make that easy for anyone did I!

The table is Called Uses! When I try to run the command on myphpadmin (v2.5.....) an erro is returned saying I have a syntax error in \'ORDER BY fileda DESC LIMIT 10\'

#4 PHPcadet

PHPcadet
  • Members
  • PipPip
  • Member
  • 14 posts
  • LocationPlant City, Florida

Posted 09 September 2003 - 01:37 PM

Check the spelling of your column names. In the error message it says \"fileda\". In your UPDATE statement it says \"fielda\". I notice with MySQL and other languages, the error messages aren\'t always exact, meaning you should look \"around\" the code for the eror, sometimes it is before, sometimes it is after. Hope this helps.
If builders built buildings the way programmers write programs, then the first termite to come along would destroy civilization -- Anonymous

#5 metalblend

metalblend
  • Members
  • PipPipPip
  • Advanced Member
  • 89 posts
  • LocationCalifornia, USA

Posted 09 September 2003 - 05:04 PM

Remember, ORDER BY is fairly new to UPDATE queries (introduced in 4.0.0).. be sure your host has MySQL 4 or later.

Other than that, there are no syntax errors in your query.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users