Results 1 to 5 of 5

Thread: Update mysql plz

  1. #1
    Join Date
    May 2006
    Posts
    266
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Update mysql plz

    Hi I cant get this code to add the next number to imp when I run this script.

    $result1 = mysql_query("UPDATE queerhuntradio_video_ads SET imp='+1' WHERE id='$row[id]' AND imp='$row[imp]'");

    So if imp is 1 it makes it 2 if 2 it makes it 3

    Please help
    The web in one word.

  2. #2
    Join Date
    May 2006
    Posts
    266
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Got it to work
    The web in one word.

  3. #3
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    Quote Originally Posted by queerfm View Post
    Got it to work
    How? Post your query if you can.

  4. #4
    Join Date
    Mar 2009
    Location
    Egypt
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by queerfm View Post
    Hi I cant get this code to add the next number to imp when I run this script.

    $result1 = mysql_query("UPDATE queerhuntradio_video_ads SET imp='+1' WHERE id='$row[id]' AND imp='$row[imp]'");

    So if imp is 1 it makes it 2 if 2 it makes it 3

    Please help
    if you want to increase imp +1 you have to get the old value at first to add 1 on it like :

    PHP Code:

    <?php

    $sql 
    "select * from queerhuntradio_video_ads where id='$row[id]' ";
    $res = @mysql_query ($sql);
    $result = @mysql_fetch_array($res);

    $old_value $result[imp];
    $new_value $old_value +;

    $result1 mysql_query("UPDATE queerhuntradio_video_ads SET imp='$new_value' WHERE id='$row[id]' AND imp='$row[imp]'");
    Try it and let me know the result .

  5. #5
    Join Date
    Mar 2009
    Posts
    65
    Thanks
    13
    Thanked 4 Times in 4 Posts

    Default

    I believe it is possible in SQL to set something like tmp=tmp + 1

    So:

    PHP Code:
    update table where table.id 1 SET value value 
    Here's a link to clear up things up.

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
  •