nicholas.alipaz Posted July 2, 2008 Share Posted July 2, 2008 I am trying to pull a column from my database and separate it into 2 arrays. My data looks like this (these are all in one column): Array from database (needs to be separted to 2 arrays): Some Info~Other stuff More Info~More stuff Lotsa Info~Lotsa stuff I haven't had any issues pulling the data from the database, but manipulating it to become two separate arrays is what I am having trouble with. I need to end up with two separate arrays: Array 1: Some Info More Info Lotsa Stuff Array 2: Other stuff More stuff Lotsa stuff Thanks for any help you guys can give me. Link to comment https://forums.phpfreaks.com/topic/113008-php-and-mysql-column-to-multiple-arrays/ Share on other sites More sharing options...
DarkWater Posted July 2, 2008 Share Posted July 2, 2008 Some actual code and real database schemas would help a lot. =X Link to comment https://forums.phpfreaks.com/topic/113008-php-and-mysql-column-to-multiple-arrays/#findComment-580497 Share on other sites More sharing options...
nicholas.alipaz Posted July 3, 2008 Author Share Posted July 3, 2008 Ok, sorry for any confusion, I will try to describe this as clearly as possible MySQL Database: valueSome Info~Some Stuff,More Info~More Stuff,Wow Info~Wow StuffSome Info2~Some Stuff2,More Info2~More Stuff2,Wow Info2~Wow Stuff2 PHP Code: $dbhost = "localhost"; $dbuser = "root"; $dbpass = "somepass"; $dbname = "mydata"; mysql_pconnect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to MySQL server"); $pro_ent_txt=mysql_db_query($dbname,"SELECT `value` FROM mag_catalog_product_entity_text WHERE `attribute_id` = 579"); function grabArray($value) { echo "$value<br>"; } while(list($modList)=mysql_fetch_array($pro_ent_txt)){ $rawList = "$modList"; $list = explode(",",$rawList); array_walk($list,"grabArray"); } The above is what I have so far, it outputs: Some Info~Some Stuff More Info~More Stuff Wow Info~Wow Stuff Some Info2~Some Stuff2 More Info2~More Stuff2 Wow Info2~Wow Stuff2 What I actually need to output is: RESULT 1 (stuff before tilde's): Some Info More Info Wow Info Some Info2 More Info2 Wow Info2 RESULT 2 (stuff after tilde's): Some Stuff More Stuff Wow Stuff Some Stuff2 More Stuff2 Wow Stuff2 Thanks again for any help. Link to comment https://forums.phpfreaks.com/topic/113008-php-and-mysql-column-to-multiple-arrays/#findComment-580507 Share on other sites More sharing options...
nicholas.alipaz Posted July 3, 2008 Author Share Posted July 3, 2008 *bump* Link to comment https://forums.phpfreaks.com/topic/113008-php-and-mysql-column-to-multiple-arrays/#findComment-580754 Share on other sites More sharing options...
DarkWater Posted July 3, 2008 Share Posted July 3, 2008 Just explode it by ~ also and separate it based on if it has an odd or even key in the new array? Don't use that array_walk, but instead, make it an array that you can iterate through to explode by ~. Link to comment https://forums.phpfreaks.com/topic/113008-php-and-mysql-column-to-multiple-arrays/#findComment-580774 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.