Log in

View Full Version : Update mysql plz



queerfm
03-23-2009, 01:35 PM
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

queerfm
03-23-2009, 01:38 PM
Got it to work

JasonDFR
03-23-2009, 06:50 PM
Got it to work

How? Post your query if you can.

Ahmed Saleh
03-27-2009, 12:23 PM
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

$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 +1 ;

$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 .

CrazyChop
03-28-2009, 07:02 AM
I believe it is possible in SQL to set something like tmp=tmp + 1

So:



update table where table.id = 1 SET value = value + 1


Here's a link to clear up things up (http://www.tech-recipes.com/rx/2139/mysql_increment_an_exisitng_value/).