Page 1 of 1

help with sql statement, query table based on another table

Posted: 2020-02-23 20:26
by D Oliveira
Hey guys, what would be the proper way to accomplish that? update a table based on a query of another table ('membership_userrecords' based on 'meals')

hooks/recipes.php/after update function:

Code: Select all

sql("UPDATE membership_userrecords SET `groupID` = '325' WHERE `tableName` = 'meals' AND pkValue = (SELECT ID FROM meals WHERE meals.recipes_id = '{$data['id']}' )'", $eo);

Re: help with sql statement, query table based on another table

Posted: 2020-02-23 20:53
by D Oliveira
also, would the statement update all records of 'meals' that have meals.recipes_id = '{$data['id']}' )' or just one single record? need to make sure all records are updated properly

Re: help with sql statement, query table based on another table

Posted: 2020-02-24 04:25
by D Oliveira
solution ajax :) you can 'echo' using that 'if statement' to loop through it, if needed.

Code: Select all

$id = makesafe($_REQUEST['id']);
$gp = '325';
			
				sql("UPDATE `membership_userrecords` SET `groupID` = '{$gp}' WHERE `tableName` = 'recipes' AND `pkValue` = '{$id}'", $eo);


				$sql = "SELECT pkValue FROM membership_userrecords WHERE tableName = 'meals' AND groupID != '{$gp}' AND EXISTS (SELECT ID FROM meals WHERE recipes_id = '{$id}')";

				$d1 = sqlValue($sql);

				if($d1==""){

				}else{

					sql("UPDATE `membership_userrecords` SET `groupID` = '{$gp}' WHERE `tableName` = 'meals' AND `pkValue` = '{$datos}'", $eo);


				};