How do I store an array in a database as an array so when PHP pulls the data out of the database it will be treated as an array?
you can serialize it before storage and revert its serialization after retrieval using the functions serialize() and unserialize()
So, if I wanted to check whether text exsits in my database I would do something like this? PHP code: //get data from database as $data which is not an array $data = unserialize($data); //check if in array if(in_array($data, 'bob') == 0) { echo('bob does not exsist!!!'); //serialize for database serialize($data); //insert $data into database here } else { echo('bob exists!!! Hi bob!!!'); } Code (markup):
i agree with the post above, if i understood what you meant correctly, serialize it before storing then unserialize it when you fetch it from the db
i just dont know why must you store it this way, you can easily create a table for accounts where you can list each of the names? its more efficient
I did create an ip address column in my MySQL database now I want to populate it with IP addresses (each row corosponds to a specific name and each name has a list of Ip's). It is really hard to explain. I think this is the simpilest way of doing what I want, so can you please if this code will work? PHP code: //get data from database as $data which is not an array $data = unserialize($data); //check if in array if(in_array($data, 'bob') == 0) { echo('bob does not exsist!!!'); //serialize for database serialize($data); //insert $data into database here } else { echo('bob exists!!! Hi bob!!!'); } Code (markup):
You could store each IP in a new row with it's identifier being the user's name. That way you can pull a list of IP's and build the array in PHP.