Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

update_related_resource()

Description

Update related resources - add new related resource or delete existing

Parameters

ColumnTypeDefaultDescription
$ref int ID of current resource
$related int ID of resource to link to current resource
$add boolean true Add relationship?

Return

boolean

Location

include/resource_functions.php lines 5735 to 5750

Definition

 
function update_related_resource($ref,$related,$add=true)
    {    
    if (!
is_int($ref) || !is_int($related)){return false;}
    
$currentlyrelated=sql_value("select count(resource) value from resource_related where (resource='$ref' and related='$related') or (resource='$related' and related='$ref')",0);  
    if(
$currentlyrelated!=&& !$add)
        {
        
// Relationship exists and we want to remove
        
sql_query("delete from resource_related where (resource='$ref' and related='$related') or (resource='$related' and related='$ref')");  
        }
    elseif (
$currentlyrelated==&& $add)
        {
        
// Relationship does not exist and we want to add
        
sql_query("insert into resource_related(resource,related) values ('$ref','$related')");
        }
    return 
true;
    }

This article was last updated 10th July 2020 22:05 Europe/London time based on the source file dated 10th July 2020 16:06 Europe/London time.