Jump to content

Archived

This topic is now archived and is closed to further replies.

Woodie

Update help

Recommended Posts

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?

Share this post


Link to post
Share on other sites

The words \"table\" and \"tables\" are reserved words in MySQL. Not sure if that\'s your problem.

Share this post


Link to post
Share on other sites

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\'

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.