argrafic Posted April 29, 2008 Share Posted April 29, 2008 Hello all. I'm building some sort of blog and I have the field for the type of cloud or keywords from the post and I'm having tourble thinking how it works. The way I'm doing it is that you have a textfield and you enter the words separated with a space. Then when I catch the value of the textfield I explode it so I have an array of words I would insert into a table in the database associated with the id of the blog post so then I can find the posts depending on the words. But I have been batteling all morning with the array, how to break each part into a single word and then isert that word into the database. I've tried the serialized and unserialized function and can't seem to make it work!!! I hope someone can help me!! Thanks!!! Quote Link to comment https://forums.phpfreaks.com/topic/103427-help-with-array/ Share on other sites More sharing options...
nloding Posted April 29, 2008 Share Posted April 29, 2008 Have them separate the entries with a comma, then $newarray = explode(",", $array); Quote Link to comment https://forums.phpfreaks.com/topic/103427-help-with-array/#findComment-529621 Share on other sites More sharing options...
argrafic Posted April 29, 2008 Author Share Posted April 29, 2008 ??? ok... then what? i keep getting: Array instead of all the words... Quote Link to comment https://forums.phpfreaks.com/topic/103427-help-with-array/#findComment-529645 Share on other sites More sharing options...
wildteen88 Posted April 29, 2008 Share Posted April 29, 2008 Use implode to convert the array into a string, eg: $arr = array('one', 'two', 'three'); $str = implode(', ', $arr); echo $str; // OUTPUT: 'one, two, three' (without quotes) Quote Link to comment https://forums.phpfreaks.com/topic/103427-help-with-array/#findComment-529699 Share on other sites More sharing options...
argrafic Posted April 29, 2008 Author Share Posted April 29, 2008 well, i found the answer to my question!!!! $string = "This is an example"; $arrayOfString = explode(" ", $string); foreach($arrayOfString as $word) { echo '<p>The word is: '. $word . '</p>'; } so i made the tweak to use it for what i needed, this is the code i'm using: $string = $_POST['t_tema']; $arrayOfString = explode(" ", $string); foreach($arrayOfString as $word) { $sql="INSERT INTO blog_tema (t_b_id, t_tema) VALUES ('5', '$word')"; } Quote Link to comment https://forums.phpfreaks.com/topic/103427-help-with-array/#findComment-529721 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.