Jump to content

[SOLVED] Seperating Tags


AXiSS

Recommended Posts

How do you seperate phrases with comments? If you ask them for tags to describe their website, and say you type in "PHP, Coding, Web Design", how would the script seperate the 3 phrases, and store them in the database? More of, what is the best way to store tags for something in a database (I can write the DB insert script)?

 

??? Please help!

AXiSS

Link to comment
Share on other sites

Have someone enter tags that describe their site in a form. The form processes the text and enters the tags into the database. I want to know the best way to do this so it can be retrieved and the tags will be displayed seperately.

 

So:

1. User enters tags in form, seperated by comments (dont need help here)

2. Form adds tags to database (best way to do this please?)

3. Tags need to be processed as seperate, without commas, upon retrieval

 

The main thing here is the fact that each phrase seperated by commas needs to be seperated, and for all purposes they need to be seperate, and I need to know the best way to store the tags in a database.

Link to comment
Share on other sites

User enters tags in form, seperated by comments (dont need help here)

 

Do you mean commas? Not comments?

 

The easiest way would be to create a table, tags...

 

CREATE TABLE tags (
  id INT PRIMARY KEY AUTO INCREMENT,
  userid INT,
  tag VARCHAR
);

 

Then, lets say your $_POST data looks like...

 

foo,bar,boo,bob

 

Simply loop through and insert each record. eg;

 

<?php

  if (isset($_POST['tags'])) {
    $tags = explode(',',$_POST['tags']);
    foreach ($tags as $tag) {
      if (mysql_query("INSERT INTO tags (userid,tag) VALUES ('{$_SESSION['userid']}',$tag)")) {
        echo "$tag added";
      }
    }
  }

?>

 

I have assumed your users are logged in and have a session variable holding there id, but you get the idea.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.