Results 1 to 6 of 6

Thread: UPDATE query

  1. #1
    Join Date
    Aug 2007
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default UPDATE query

    Code:
    $pop=$row[pop];
    $p=1;
    $popp=($pop+$p);
    
    mysql_query("UPDATE fragrances SET pop = '$popp'
    WHERE sku=$sku");
    i'm a bit unfamiliar with the UPDATE function as opposed to the SELECT one, so i'm stumped as to why this isn't working.

    the idea behind this code is that when the page is loaded, it automatically updates the set of "pop" by 1. this works fine the first time ie. from "0" to "1".

    but now when i refresh a page or go back at a later date the pages that have the pop value of "1" aren't moving up to "2".

    i'm stumped! any ideas?

  2. #2
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    PHP Code:
    $pop=(int) $row['pop'];
    $p=1;
    $popp=($pop+$p);

    mysql_query("UPDATE `fragrances` SET `pop` = '$popp' WHERE `sku`='$sku'"); 
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    mysql_query('update fragrances set pop = pop + 1 where sku = ' . $sku);
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Nov 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Another way is to simply...

    PHP Code:
    mysql_query("UPDATE `fragrances` SET `pop` = `pop`+1 WHERE `sku`='$sku'"); 

  5. #5
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Same code.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  6. #6
    Join Date
    Nov 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I didn't scroll down far enough to read the rest of the posts...

Bookmarks

Posting Permissions

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