+ Reply to Thread
Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By gomarc

Thread: MySQL reducing column integer values by 1

  1. #1
    learning_brain is offline x10 Sophmore learning_brain is an unknown quantity at this point
    Join Date
    Apr 2010
    Location
    UK, Midlands
    Posts
    170

    MySQL reducing column integer values by 1

    Hi

    This may seem simple but it not working for me.

    I currently have the following:

    PHP Code:
    UPDATE images SET POPULAR POPULAR -1 WHERE POPULAR 
    All I want is to reduce each individual value by one less than the current stored value. Google doesn't seem to give me the answer!

    What this statement is doing is taking the first value it finds and using that as the value to update all other fields with the same value... not good.

    Do I really have to create a loop for this???????

    There must be a simpler mySQL solution...

    Rich
    Last edited by learning_brain; 07-24-2011 at 09:40 AM.

  2. #2
    gomarc's Avatar
    gomarc is offline x10 Elder gomarc is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    USA
    Posts
    511

    Re: MySQL reducing column integer values by 1

    Hi learning_brain,

    There has to be something else affecting the result you expect.

    If this is a one time thing, you may want to run your update query from phpMyAdmin and you'll see that it is in fact reducing each individual value of 'POPULAR' by one less than the current stored:



    Make sure you backup your database, and select the appropriate database/table/SQL tab before running this query. It will work just fine.
    learning_brain likes this.

  3. #3
    learning_brain is offline x10 Sophmore learning_brain is an unknown quantity at this point
    Join Date
    Apr 2010
    Location
    UK, Midlands
    Posts
    170

    Re: MySQL reducing column integer values by 1

    Hmm - you're right.

    Something else must be amiss.....

    I'll keep digging.

    ---------- Post added at 07:08 PM ---------- Previous post was at 06:21 PM ----------

    Sorry - just worked it out.

    I didn't include the whole statement for ease of understanding but there was another variable control which had a conflict with NULL values.

    Job sorted.

    Rich

+ Reply to Thread

Similar Threads

  1. Exporting a Csv File with zeros as the first integer
    By tillabong in forum Programming Help
    Replies: 14
    Last Post: 07-30-2011, 01:28 PM
  2. MySQL Total Column
    By councils in forum Programming Help
    Replies: 3
    Last Post: 02-11-2011, 08:06 PM
  3. 10 Tips for reducing web site bandwidth
    By cybrax in forum Tutorials
    Replies: 5
    Last Post: 01-12-2011, 08:04 PM
  4. PHP/SQL: Increment Integer Value in Database via Form
    By shawntc in forum Programming Help
    Replies: 7
    Last Post: 07-12-2010, 12:05 PM
  5. Mysql help needed: getting number of items in table column
    By xprtweb in forum Programming Help
    Replies: 1
    Last Post: 02-23-2008, 01:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers