Page 1 of 1

two table update

Posted: Thu Nov 17, 2005 9:52 pm
by joecrack
I want to have a IF after my update command that looks like this:

Code: Select all

if($cortval1>0,$cortval2>0,$cortval3>0){
	$tovalue='$tovalue+$cortval1+$cortval2+$cortval3';
}
	elseif($cortval1>0,$cortval2>0){
		$tovalue='$tovalue+$cortval1+$cortval2';
	}
		elseif($cortval1>0){
		$tovalue='$tovalue+$cortval1';
		}
But $tovalue is from a different table than the cortval1-3
Can i do it like this???

Code: Select all

elseif($cortval1>0){
$sql = "UPDATE sam_artikel SET $tovalue=$tovalue+$conrtval1";
mysql_query($sql);
}

Re: two table update

Posted: Fri Nov 18, 2005 12:42 am
by nigma
joecrack wrote:

Code: Select all

if($cortval1>0,$cortval2>0,$cortval3>0){
	$tovalue='$tovalue+$cortval1+$cortval2+$cortval3';
} ...
Is that supposed to be pseudocode?
joecrack wrote:Can i do it like this???

Code: Select all

elseif($cortval1>0){
$sql = "UPDATE sam_artikel SET $tovalue=$tovalue+$conrtval1";
mysql_query($sql);
}
What output do you expect "$tovalue=$tovalue+$conrtval1" to produce? Are $tovalue and $conrtval1 integers that you want to add? Or are they just chunks of data that you want to place an addition sign between in your sql query?

Posted: Fri Nov 18, 2005 1:34 am
by joecrack
Both are integers.
So i just want to sum them together.
Yeah the if command was <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> ...-.... excuse me :roll:
BUt do you understand what i want to do.
If cortval3 has a value, then i want to add cortval1-3 to toval .. and to val is in a different table.!!!

Posted: Fri Nov 18, 2005 5:45 am
by twigletmac
You can run an UPDATE using multiple tables and their data:
http://dev.mysql.com/update

Mac

Posted: Fri Nov 18, 2005 12:37 pm
by nigma
Also, if you want to add two variables you can't do it with double quotes around. I.e.

Code: Select all

$newvar = "$var1+$var2";
won't work. But

Code: Select all

$newvar = $var1+$var2;
will.