Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 array and database
Index -> Programming, PHP -> PHP Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Homer_simpson




PostPosted: Sun Sep 14, 2003 12:25 pm   Post subject: array and database

is it possible to have an array of text as a field in your database?
Sponsor
Sponsor
Sponsor
sponsor
rizzix




PostPosted: Sun Sep 14, 2003 12:35 pm   Post subject: (No subject)

ur trying to store a complex datatype. if ur database supports it you can. i know oracle does. not sure of mysql. anyhow just convert that array of text to a single string, then store that string. that will work anyhow.
Homer_simpson




PostPosted: Sun Sep 14, 2003 12:40 pm   Post subject: (No subject)

well i'll just do this:
Use a text field... and put all my texts there and separate them with a special character like Þ then use this function to break it down into an array:
code:
function analyze($ass){
$parr=array();
$tmpstr="";
$arrc=0;
for($i=0;$i<strlen($ass);$i+=1){
        if($ass[$i]=="Þ")
                {
                        $parr[$arrc]=$tmpstr;
                        //echo $tmpstr;
                        $tmpstr="";
                        $arrc+=1;
                }
        else    {
                        $tmpstr=$tmpstr.$ass[$i];
                }

}
return $parr;
}



so now if $text="picture1.jpgÞpicture2.jpgÞsomethingÞ"

when i pass it through my function the return array will be like this:
arr[0]=picture1.jpg
arr[1]=picture2.jpg
arr[2]=something


hopefully this we'll solve yer problem if u had the same problem as i did..
rizzix




PostPosted: Sun Sep 14, 2003 12:56 pm   Post subject: (No subject)

eh what!!! u solved ur own problem Confused thats nice Confused
Homer_simpson




PostPosted: Sun Sep 14, 2003 1:23 pm   Post subject: (No subject)

rizzix wrote:
eh what!!! u solved ur own problem Confused thats nice Confused

lol... i knew how to do that.... i wanted to know if there's a proper way to di it so i wouldn't have to extract strings from eachother... Confused
octopi




PostPosted: Sun Sep 14, 2003 1:43 pm   Post subject: (No subject)

I am pretty sure this is what you want.

http://ca.php.net/serialize
http://ca.php.net/unserialize
PaddyLong




PostPosted: Sun Sep 14, 2003 1:49 pm   Post subject: (No subject)

heh you do know that php provides a function to split strings into an array at certain a expression? split ... http://ca2.php.net/manual/en/function.split.php
Homer_simpson




PostPosted: Sun Sep 14, 2003 2:55 pm   Post subject: (No subject)

PaddyLong wrote:
heh you do know that php provides a function to split strings into an array at certain a expression? split ... http://ca2.php.net/manual/en/function.split.php

lol... no i had no idea that php does that... but i'm still happy with the way i'm working my database and separating them manually...
rizzix




PostPosted: Sun Sep 14, 2003 9:30 pm   Post subject: (No subject)

if i were you, i'd go with octopi's recommendation: serialization. Since using that method you can even store Objects in the database.
Homer_simpson




PostPosted: Mon Sep 15, 2003 5:48 pm   Post subject: (No subject)

well yes that's not a bad idea... but currently all i need is to save simple strings into a field and i find sperating the strings easier to do... but if i wanna store more complex data then i'll use that method...
octopi




PostPosted: Mon Sep 15, 2003 6:58 pm   Post subject: (No subject)

First off you make no sense in your posts, and you keep contradicting yourself....and heres an anwser using the methods I explained.....I don't see how this is harder or more complex...it does the exact thing, but in a better way, and probally more efficient way.


code:
$array = array('one', 'two', 'three');
$stringofarray = base64_encode(serialize($array));
$query = "insert into phparray values('',$stringofarray)";
mysql_query($query);
$query = "select data from phparray where id=0";
$result = mysql_query($query);
$newarray = unserialize(base64_encode(mysql_fetch_array($result)));

Untested because...I am not going to put that much effort into a solution for you.


Why would you ask for an anwser to a question you have already solved...and then not even use the anwsers...
Display posts from previous:   
   Index -> Programming, PHP -> PHP Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: