Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video 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 6102 to 6117

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 1st December 2020 23:05 Europe/London time based on the source file dated 30th November 2020 11:55 Europe/London time.