Jump to content

PHP and MySQL column to multiple arrays


Recommended Posts

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

Ok, sorry for any confusion, I will try to describe this as clearly as possible

 


MySQL Database:

value
Some Info~Some Stuff,More Info~More Stuff,Wow Info~Wow Stuff
Some 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. :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.