two table update

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

two table update

Post 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);
}
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Re: two table update

Post 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?
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post 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.!!!
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You can run an UPDATE using multiple tables and their data:
http://dev.mysql.com/update

Mac
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post 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.
Post Reply