Argh... I want to delete a part of a function... People can choose either to delete a foreign key from table Pages. (radiobutton == 1) Or to delete the section in all, including the foreign keys found in pages.
database tablestructure:
pages(id,subcat,txt,sections) sections foreign key sections.id
sections(id,title)
links(id,section,txt,title) section foreign key sections.id
pages.sections can contain 0,1 or more sectionids.
(db sucks, I know... cannot help it at this time)
so this is what I came up with:
However, when I execute this script, it doesn't remove the sectionid from the pages-table... and when I want to remove it completely, it only removes it from the sections-table... not the pages table.PHP Code:if($radiobutton == '1'){
$sql = "UPDATE pages SET sections =
REPLACE(sections,'$sectionid,',''), // removes i.e. sectionid 12 if value = 12,13,14
REPLACE(sections,',$sectionid',''), // removes i.e. sectionid 12 if value 11,12,13 or 10,11,12
REPLACE(sections,'$sectionid','') // removes i.e. sectionid 12 if value 12
WHERE subcat = '$subcatid2'";
$result = mysql_query($sql);
print "Section number <b>$sectionid</b> has been removed from this page <br>";
}
else {
$sql = "UPDATE pages SET sections =
REPLACE(sections,'$sectionid,',''), // removes i.e. sectionid 12 if value = 12,13,14
REPLACE(sections,',$sectionid',''), // removes i.e. sectionid 12 if value 11,12,13 or 10,11,12
REPLACE(sections,'$sectionid','') // removes i.e. sectionid 12 if value 12
WHERE subcat = '$subcatid2'";
$result = mysql_query($sql);
$sql2 = "DELETE FROM sections WHERE id = '$sectionid'";
$result2 = mysql_query($sql2);
$sql3 = "DELETE FROM links WHERE section = '$sectionid'";
$result3 = mysql_query($sql3);
print "Section number <b>$sectionid</b> has been removed from the database <br>";
}
Where did I go wrong? Please advise





Bookmarks