help with sql statement, query table based on another table

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

help with sql statement, query table based on another table

Post by D Oliveira » 2020-02-23 20:26

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);

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

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

Post by D Oliveira » 2020-02-23 20:53

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

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

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

Post by D Oliveira » 2020-02-24 04:25

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);


				};

Post Reply