Jump to content


This topic is now archived and is closed to further replies.


Need help completing tagging input

Recommended Posts

I am a bit confused but here is what ive done:

Users insert tags VIA a textarea IE:

| rap, hip-hop, jungle |

Then I explode the ones into an array, then I did a foreach statement to insert each into separate rows in the "tags_relations" table

Then I went ahead further and brought the tags back together to display in the textarea box on submit, so after a user submits those tags above it will show:

| rap, hip-hop, jungle |

in the textarea, so what I want to do now is make it easyer to delete the tag by just removing it from the textarea like(so the user deletes ", jungle" from the list:

| rap, hip-hop |

The problem is that I have no idea on how to remove the tag "jungle" from the tags_relations table, ive asked around and people told me to use array_diff, but ive try multiple times trying to get it to work but nothing


$act = $_GET[action];
  $torrentid = (int) $_GET['id'];
        if (!isset($torrentid) || !$torrentid)

if($act == "taketag") {
      $before = $_POST['tags'];
      //If nothing is in the box delete all the tags
        mysql_query("DELETE FROM tags_relations WHERE tagger_id=$CURUSER[id] AND torrent_id=$torrentid");
      //Make it lowercase
      $lower = strtolower($before);
      //Remove a comma if its the last char.
      $text = trim($lower);
      $last = $text{strlen($text)-1};
      if (!strcmp($last,",")){
        $text = rtrim($text, 'a..z');
        $text = rtrim($text, ',');
              //Explode all tags into an array
      $tags = explode(',',$text);
              //Split each and do w/e to each one
      foreach($tags as $tag) {
                $tag = trim($tag);

        $tagsql = mysql_query("SELECT tag_id FROM tags WHERE tag_name='".mysql_escape_string($tag)."'") or die(mysql_error());
          $result = mysql_fetch_assoc($tagsql);

            if (!$result) {
              @mysql_query ("INSERT INTO tags (tag_name, tag_owner) VALUES ('".mysql_escape_string($tag)."', '".$CURUSER['id']."')") or die(mysql_error());
              $tagId = mysql_insert_id();
            } else {
              $tagId = $result['tag_id'];
              @mysql_query ("INSERT INTO tags_relations (torrent_id, tag_id, tagger_id, tag_name) VALUES ('".$torrentid."', '".$tagId."', '".$CURUSER['id']."', '".mysql_escape_string($tag)."') ON DUPLICATE KEY UPDATE tag_id='".$tagId."',torrent_id='".$torrentid."', tagger_id='".$CURUSER['id']."'") or die(mysql_error());

if($act == "reset") {
        mysql_query("DELETE FROM tags_relations WHERE torrent_id=$torrentid AND tagger_id = $CURUSER[id]");

stdhead('Add Request Page');

$torrentid = (int) $_GET['id'];
if (!isset($torrentid) || !$torrentid)

$rre = mysql_query("SELECT * FROM tags LEFT JOIN tags_relations tr ON tr.tagger_id = $CURUSER[id] AND tr.torrent_id = $torrentid WHERE tr.tag_id = tags.tag_id ORDER BY tags.tag_name ASC");
while($arr = mysql_fetch_array($rre)){
      if ($tagsw)
      $tagsw .= ", ";
      $tagsw .= $arr['tag_name'];

$res = mysql_query("SELECT name FROM torrents WHERE id=$torrentid");
$rawr = mysql_fetch_assoc($res);

<form method="post" action="tag.php?id=<?=$torrentid?>&action=taketag">
<table width=750 cellspacing=0 cellpadding=5>
<tr><td colspan=2 class=tabletitle align=left><b>Tag <?=$rawr[name]?>.</b></td></tr>
<tr><td colspan=2 class=tableb align=left>Separate tags by a comma.  Ex.: punk, hardcore, ska<br>
<textarea value="<?=$tagsw?>" name="tags" rows="6" cols="80"><?=$tagsw?></textarea>
<tr><td colspan=2 class=tableb align=left>Click <a class=altlink href="tag.php?action=reset&id=<?=$torrentid?>">here</a> to remove all tags you have put on this torrent.</td></tr>
<tr><td colspan=2 class=tableb align=left><input type=submit value=Submit style='height: 20px'></td></tr>

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.