richardjh Posted June 4, 2009 Share Posted June 4, 2009 This is a follow on from a thread I posted for help but alas I'm still stuck so I'm struggling through bit by bit myself. Could someone advise me how I can split a string of words (sentence) into separate words to place into an Array and then place each array element into a mysql table? I've tried and tried to do it myself and failed miserably! I really need an expert. thanks and sorry for being a pest R Link to comment https://forums.phpfreaks.com/topic/160916-adding-an-array-to-database/ Share on other sites More sharing options...
.josh Posted June 4, 2009 Share Posted June 4, 2009 $string = "some random text"; $string = explode(" ",$string); foreach ($string as $w) { $sql = "insert into table (column) values ('$w')"; $result = mysql_query($sql); } Link to comment https://forums.phpfreaks.com/topic/160916-adding-an-array-to-database/#findComment-849208 Share on other sites More sharing options...
The Spook Posted June 4, 2009 Share Posted June 4, 2009 Also, you can store arrays in a database with JSON (req PHP 5.2+ or JSON lib). $array = array("some", "random", "text"); $sql = "INSERT INTO table (column) VALUES ('".mysql_real_escape_string(json_encode($array))."')"; And to retrieve the value back into an array: $result = mysql_query("SELECT column FROM table WHERE ID=1"); $row = mysql_fetch_array($result); $array = json_decode($row['column']); print_r($array); Link to comment https://forums.phpfreaks.com/topic/160916-adding-an-array-to-database/#findComment-849255 Share on other sites More sharing options...
.josh Posted June 4, 2009 Share Posted June 4, 2009 ..and you would store it in the db so....you can make it that much harder to select/filter information...why? Link to comment https://forums.phpfreaks.com/topic/160916-adding-an-array-to-database/#findComment-849267 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.