AXiSS Posted February 8, 2007 Share Posted February 8, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/37680-solved-seperating-tags/ Share on other sites More sharing options...
trq Posted February 8, 2007 Share Posted February 8, 2007 Your question is extremely vague. What exactly are you trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/37680-solved-seperating-tags/#findComment-180241 Share on other sites More sharing options...
AXiSS Posted February 8, 2007 Author Share Posted February 8, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/37680-solved-seperating-tags/#findComment-180245 Share on other sites More sharing options...
trq Posted February 8, 2007 Share Posted February 8, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/37680-solved-seperating-tags/#findComment-180251 Share on other sites More sharing options...
AXiSS Posted February 9, 2007 Author Share Posted February 9, 2007 OK, I think I can take that and apply it. Quote Link to comment https://forums.phpfreaks.com/topic/37680-solved-seperating-tags/#findComment-180295 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.