Hi
I have been trying to find a solution but have had no luck.
I am trying to take the $_POST array and implode its key=value into one string that I can later explode.
Does anyone have any solution???
Example of desired array to string outcome:
$all_items = item1=23|item2=12|item3=45 .... etc...
The end result string will be inserted into the db(all into one field)
Please let me know if you have any ideas... Thank you!
Working with $_POST array
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
I think you want to use serialize() instead.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Yea its pretty simple, although I'm not exactly sure on how you want to handle capturing your data. I'm assuming that you want to capture all form fields and insert them into a column.
Now when you want to get your array into usable form simply use unserialize()
Code: Select all
$array = serialize($_POST);
$query = 'INSERT INTO `table` SET `column = \''.$array.'\'';
$result = mysql_query($query) or die(mysql_error());Code: Select all
$str="";
foreach($_POST as $key=>$value) {
// do any cleaning/filter here. calling continue if this item should be skipped
if ($str!="") $str.="|";
$str.="$key=$value";
}Code: Select all
$string = "item1=".$_POST['item1']."|item2=".$_POST['item2']."|item3=".$_POST['item3']."";Then later, to explode
Code: Select all
explode("|", $data);Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.