Jump to content

Search the Community

Showing results for tags 'serialize'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 2 results

  1. The following serialized string is being pulled from the meta data of a Woocommerce product. a:2:{s:17:"set_51fb76f97cc57";a:6:{s:15:"conditions_type";s:3:"all";s:10:"conditions";a:1:{i:1;a:2:{s:4:"type";s:8:"apply_to";s:4:"args";a:2:{s:10:"applies_to";s:5:"roles";s:5:"roles";a:1:{i:0;s:14:"trade_customer";}}}}s:9:"collector";a:1:{s:4:"type";s:7:"product";}s:4:"mode";s:5:"block";s:5:"rules";a:1:{i:1;a:4:{s:4:"from";s:0:"";s:2:"to";s:0:"";s:4:"type";s:14:"price_discount";s:6:"amount";s:0:"";}}s:10:"blockrules";a:1:{i:1;a:5:{s:4:"from";s:1:"*";s:6:"adjust";s:1:"1";s:4:"type";s:16:"fixed_adjustment";s:6:"amount";s:4:"8.37";s:9:"repeating";s:3:"yes";}}}s:17:"set_51fb76f97d6a2";a:6:{s:15:"conditions_type";s:3:"all";s:10:"conditions";a:1:{i:1;a:2:{s:4:"type";s:8:"apply_to";s:4:"args";a:2:{s:10:"applies_to";s:5:"roles";s:5:"roles";a:1:{i:0;s:19:"bulk_trade_customer";}}}}s:9:"collector";a:1:{s:4:"type";s:7:"product";}s:4:"mode";s:5:"block";s:5:"rules";a:1:{i:1;a:4:{s:4:"from";s:0:"";s:2:"to";s:0:"";s:4:"type";s:14:"price_discount";s:6:"amount";s:0:"";}}s:10:"blockrules";a:1:{i:1;a:5:{s:4:"from";s:1:"*";s:6:"adjust";s:1:"1";s:4:"type";s:16:"fixed_adjustment";s:6:"amount";s:5:"9.428";s:9:"repeating";s:3:"yes";}}}} I also have this function which I am writing in order to pull out the variable product data and display it on the site: function mi_price_adjust(){ global $post, $current_user, $user_roles; $meta = get_post_meta($post->ID); $curPrice = (float)$meta['_regular_price'][0]; $variations = unserialize($meta['_pricing_rules'][0]); $user_roles = $current_user->roles; $theRoll = ''; $thePrice = $curPrice; foreach($user_roles as $miroll){ if(in_array($miroll, $user_roles)){ $theRoll = $miroll; } } if($theRoll != ''){ foreach($variations as $curvar){ $var_roll = $curvar['conditions'][1]['args']['roles'][0]; $var_cost = (float)$curvar['blockrules'][1]['amount']; if($var_roll == $theRoll){ $thePrice = $curPrice - $var_cost; } } } if($thePrice != $curPrice){ return "<strike>".$curPrice."</strike><br /><span class=\"youpayText\">You pay £$thePrice</span>"; }else{ return $thePrice; } } Everything is working fine apart from one thing. I am getting the following error: Invalid argument supplied for foreach The line in question is foreach($variations as $curvar){ And the $variations variable is being populated using this: $variations = unserialize($meta['_pricing_rules'][0]); Which returns the serialized string at the top of this post. Can anyone shed any light on why this might be happening and what we might be able to do to either fix it or circumvent it?
  2. I looking for a good tutorial that will cover arrays, from HTML forms to storing the data( serialize,unserialize, implode, explode)in mysql with php I need to create a from that will allow me to create an array from text field then submit to database and late allow me to editied and update that array So I have four basic tables one serving as main table that will hold 5 field of data plus three field set aside for arrays then I have 3 tables that will hold keys and reference for those array plus additional data objective : In my main table the fields array1 array2 and array3 are the one I need to insert the array data into. I need to be able to manipulate the data of the array completely from an HTML form or multiple forms create basic HTML forms and PHP code to process I must be able to pull a record, check to see if that is an in those field array then add some data if their is if not start a new array for that record create basic HTML forms and PHP code to process I must be able to view and delete part of the array as well create basic HTML forms and PHP code to process then pull a record that has array data in it, then create a query base on those array to pull data from other tables and create some basic calculation base on the original record and the data that you reference in the other tables ( tables array1 array2 and array3 )create basic HTML forms and PHP code to process To help paint you better picture I am attaching below some sample tables and data I know that the data is not optimize but that is on purpose ok let say that this is( id) 2 in main 2 11 12 12 15 18 ('MOPQY4IV','9QR4TH7K','NZ1O45B0','1XUUU5D4','J94RVSNY')NULL NULL this array would be reference in table array1 'MOPQY4IV','9QR4TH7K','NZ1O45B0','1XUUU5D4','J94RVSNY' So in PHP I need to create a for loop that would take the value of this array and pull the data from table array1 I don't think the foreign key would work as this is not normalize database since other (id) in main could reference the same keys in array1 so I believe it be a many to many relation (id)3 could look some like this 3 10 16 12 17 14 ('MOPQY4IV','9QR4TH7K','JAM39TXN',)NULL NULL some of the array value are the same as in (id) 2 Thank You Antonio CREATE TABLE IF NOT EXISTS `array1` ( `id` int(11) NOT NULL AUTO_INCREMENT, `arrayKey` varchar( NOT NULL, `data1` int(11) NOT NULL, `data2` int(11) NOT NULL, `data3` int(11) NOT NULL, `data4` int(11) NOT NULL, `data5` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ; -- -- Dumping data for table `array1` -- INSERT INTO `array1` (`id`, `arrayKey`, `data1`, `data2`, `data3`, `data4`, `data5`) VALUES (1, 'MOPQY4IV', 0, 1, 0, 3, 2), (2, '9QR4TH7K', 2, 2, 0, 0, 2), (3, '8NBYRZ72', 2, 1, 3, 3, 3), (4, 'NZ1O45B0', 0, 2, 2, 3, 2), (5, 'Y7XPA7Q3', 0, 0, 1, 1, 2), (6, '1XUUU5D4', 1, 3, 2, 1, 2), (7, 'JVUI1KA6', 2, 1, 3, 3, 1), (8, 'J94RVSNY', 3, 2, 3, 1, 1), (9, 'NF9YSEF4', 2, 3, 0, 1, 3), (10, 'LFY81TBA', 1, 1, 1, 3, 1), (11, 'LZH9S2DE', 0, 3, 2, 0, 1), (12, '7XK4NF8M', 3, 1, 1, 2, 0), (13, 'JAM39TXN', 0, 0, 2, 2, 1); -- -------------------------------------------------------- -- -- Table structure for table `array2` -- CREATE TABLE IF NOT EXISTS `array2` ( `id` int(11) NOT NULL AUTO_INCREMENT, `arrayKey` varchar( NOT NULL, `data1` int(11) NOT NULL, `data2` int(11) NOT NULL, `data3` int(11) NOT NULL, `data4` int(11) NOT NULL, `data5` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ; -- -- Dumping data for table `array2` -- INSERT INTO `array2` (`id`, `arrayKey`, `data1`, `data2`, `data3`, `data4`, `data5`) VALUES (1, 'BZGZX887', 1, 0, 0, 0, 3), (2, 'WW7JG2WI', 3, 1, 0, 2, 0), (3, 'U1UAK4Z7', 0, 2, 2, 3, 0), (4, 'L1ETC8VM', 1, 3, 3, 3, 3), (5, 'RYPO75Y6', 3, 3, 0, 1, 0), (6, 'O9XKS4B0', 2, 2, 2, 2, 0), (7, 'A1W8VD5M', 1, 1, 0, 3, 3), (8, '4EH4IUBF', 1, 3, 3, 2, 0), (9, '2YV7VJML', 0, 2, 0, 1, 1), (10, '1V9TPRT8', 1, 2, 3, 3, 1), (11, '6XC0QJPB', 1, 2, 2, 3, 3), (12, 'JWX4SG1M', 2, 2, 3, 1, 0), (13, '60UBRIB2', 0, 0, 2, 2, 0); -- -------------------------------------------------------- -- -- Table structure for table `array3` -- CREATE TABLE IF NOT EXISTS `array3` ( `id` int(11) NOT NULL AUTO_INCREMENT, `arrayKey` varchar( NOT NULL, `data1` int(11) NOT NULL, `data2` int(11) NOT NULL, `data3` int(11) NOT NULL, `data4` int(11) NOT NULL, `data5` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ; -- -- Dumping data for table `array3` -- INSERT INTO `array3` (`id`, `arrayKey`, `data1`, `data2`, `data3`, `data4`, `data5`) VALUES (1, 'XW2R8FZV', 0, 2, 0, 2, 1), (2, 'U0UQ4XE0', 3, 3, 3, 2, 1), (3, 'DJZ0F72P', 0, 2, 0, 2, 1), (4, '58NZG2QT', 3, 0, 3, 1, 0), (5, '8X0MTA7C', 3, 3, 1, 3, 0), (6, '566JPHPO', 3, 1, 0, 2, 2), (7, '59FE3PVA', 3, 0, 2, 3, 1), (8, 'O87PI80J', 1, 2, 0, 3, 3), (9, 'J69OP30N', 1, 2, 0, 2, 2), (10, '4VCA5FA9', 2, 1, 1, 3, 3), (11, 'N6I82WQS', 2, 0, 3, 0, 2), (12, 'ZSNV3O7K', 0, 0, 2, 2, 3), (13, 'YE6E4RB0', 2, 2, 3, 1, 0); -- -------------------------------------------------------- -- -- Table structure for table `main` -- CREATE TABLE IF NOT EXISTS `main` ( `id` int(11) NOT NULL AUTO_INCREMENT, `data1` int(11) NOT NULL, `data2` int(11) NOT NULL, `data3` int(11) NOT NULL, `data4` int(11) NOT NULL, `data5` int(11) NOT NULL, `array1` text, `array2` text, `array3` text, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=17 ; -- -- Dumping data for table `main` -- INSERT INTO `main` (`id`, `data1`, `data2`, `data3`, `data4`, `data5`, `array1`, `array2`, `array3`) VALUES (1, 10, 11, 15, 14, 16, NULL, NULL, NULL), (2, 11, 12, 12, 15, 18, NULL, NULL, NULL), (3, 10, 16, 12, 17, 14, NULL, NULL, NULL), (4, 18, 10, 13, 16, 11, NULL, NULL, NULL), (5, 11, 10, 13, 9, 15, NULL, NULL, NULL), (6, 9, 18, 14, 17, 14, NULL, NULL, NULL), (7, 14, 18, 16, 13, 17, NULL, NULL, NULL), (8, 15, 16, 12, 17, 17, NULL, NULL, NULL), (9, 17, 16, 12, 14, 10, NULL, NULL, NULL), (10, 17, 14, 11, 9, 17, NULL, NULL, NULL), (11, 12, 18, 10, 13, 13, NULL, NULL, NULL), (12, 10, 12, 14, 14, 10, NULL, NULL, NULL), (13, 14, 14, 12, 17, 18, NULL, NULL, NULL), (14, 1, 1, 1, 1, 1, NULL, NULL, NULL), (15, 22, 22, 22, 22, 22, NULL, NULL, NULL), (16, 1, 1, 1, 1, 1, NULL, NULL, NULL);
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.