Hello! I am budiling my own tags system. So when i post news, i have tags files, where i insert tags : some1,some2,some3 ... So now i want these tags to be each own for news. So every tag is one record for news. Because i want to make that they will click on tag and it will show all news with that tag. It cannot work if i won't have array of tags for each news or something. Because now some1,some2,some3 are one records and they are all with "," ... I want each tag own record for one news. How can i get array from input field, and insert into mysql database, how to read it. Any other option than array? Maybe trim() function? Thank you !
Use explode to split the values: $array = explode(",", $value_from_mysql); PHP: Would return something like; $array[] = 'some1'; $array[] = 'some2'; etc PHP: Or am I getting your question wrong?
My first ideea on this : You can use mysql "like": $q=mysql_query("Select * from test where name like '%{$query}%'"); While($r=mysql_fetch_array($q)) { echo $r['id']."-".$r['name']; echo "<br/>"; } Code (markup): I hope you got what i meant. Codebreaker. That will get all entries where one of the tags it's the query.
Hi! Thanx for that.. So i will get arrays out from database. That means " , " will get deleted and each tag in it's own array. But how can i insert arrays in database, so that i can create search script. Because i think your code is just for selecting from database and show it. Am i right ? Thanx for that, but i don't know what you mean with that. This is just a simple select from database code which i can use for search. Or i am wrong ?
Yes, it's supposed to select from the database. You can use implode to add a array to the database: $stringFromArray = implode(",", $array); PHP:
Hii! So i should use this right ? What i will got ? Each tag own record, or deleting ever " , " from this.. I really don't get it $tags = $_POST[tags]; $tags1 = implode(",", $tags); $sql="INSERT INTO news (title, newstext, postdate,tags) VALUES ('$_POST[title]','$_POST[newstext]','$_POST[date]','" .$tags1. "')"; PHP:
implode wont do anything as $_POST['tags'] isn't a array, so can you show me what is passed on to $_POST['tags']? And you have a few PHP errors, wanted to fix them but I want this to be sorted out first.
IF i get you right you have a list of posts. And every post has some tags : Example : PoSt 1 tags : max,big,cars Post 2 tags: huge,cars Post 3 tags : no, matter. And you want to get all posts with tag cars : Then you do it like i said and in that while you will have the datas of that posts. That's the thing when you use like.
Yes for search script i can use like, which will search for specific tag.. But what about if i want to show list of tags. So i select from database all tags. In your example i will got: max,big,cars, huge,cars,no, matter. $tag = $row[tags] Let's say i want to link each tag to : tag.php?tag=" .$tag. " That will give me max,big,cars like ONE tag.. so i will got tag.php?tag=max,big,cars I want EACH tag as own record.. So i can have tag.php?tag=max;tag.php?tag=big;tag.php?tag=cars And then i will check for all news with that tag. Because tags i insert into input field when writing news, are ALL ONE .. that's wrong .. I want all tags before " , " as own record for each news.