I have been trying to figure out an efficient way of updating the value in a field without having to run 2 queries.
What I would like to do is to be able to run something like this:
$link_id=db_connect();
$value_added=1;
$qid=134;
$result=mysql_query("UPDATE table1 SET value=value +'$value_added' WHERE qid='$q1'",$link_id) or die(mysql_error());};
I am getting an error in my SQL sytax.
I have also tried:
$result=mysql_query("UPDATE table1 SET value +='$value_added' WHERE qid='$q1'",$link_id) or die(mysql_error());};
The best way that I know(think) would work would be to use:
$link_id=db_connect();
$value_added=1;
$qid=134;
//to get the original value
$result=mysql_query("SELECT value FROM table1 WHERE qid='$q1'",$link_id) or
die(mysql_error());};
$pulled=mysql_fetch_array($result);
$new_value=$pulled[value] + $value_added;
//to update to the new value
$result=mysql_query("UPDATE table1 SET value='$new_value' WHERE qid='$q1'",$link_id) or die(mysql_error());};
I believe this would work, but I would much rather do one query vs. having to do 2. 1 query is twice as fast.
Thanks,
Bryan