Aloha everyone,
It seems to me that maybe now I can post a question and someone will help (I have this problem with posting questions and they dont get answered, its a family curse or something 🙂 ).
Its probably a very simple problem that I have overlooked because I am trying to just get this done, it has been a real pain in the rear getting it working.
I will post the code, and hopefully someone can help me out, I just dont get it, because it has worked every other time i have implemented it on a system.
but the data is very squirley. The data is output from spss (you dont really need to know what that is to help). and then i have a script that takes out all the crap that spss puts into its files, and then it turns the file into a sectioned comma delimited file.
then this script allows you to select how many files you want to open, asks you what database you are uploading to (currently only supports mysql right now). and then it cuts one file into strings using the /n as the explode seperator.
the file is then sectioned into arrays, with peices of the file in each section of the array.
each string looks like this until you hit the Data in this case the data starts at F (F is the data identifier), followed by the data, then another data id'er M, and ect... till the end of the string.
SEX,Frequency,Percent,ValidPercent,CumulativePercent,Valid,F,627,60.5,60.5,60.5,M,409,39.4,39.4,99.9,uk,1,.1,.1,100.0,Total,1037,100.0,100.0,
each string contains a table name, the first word and then a comma, then the field names, then a data identifier then the data, followed by another data id, then more data ect.
now the program loops after the last field name, and loops through the data storing each variable in an array.
array(4) { [0]=> string(3) "627" [1]=> string(3) "409" [2]=> string(1) "1" [3]=> string(4) "1037" }
then the data is looped into a mysql database like so:
$l = 0;
$cnnt = count($data12);
while($l < $cnnt)
{
echo "<br> INSERT INTO ".$tablename." <br> SET dataset =".$dataset2[$l]."<br>".$field1."=".$data12[$l]."<br> ".$field2."=".$data22[$l]."<br> ".$field3."=".$data32[$l]."<br> ".$field4."=".$dataname42[$l]."<br>";
$query = "INSERT INTO $tablename SET dataset='$dataset2[$l]',$field1='$data12[$l]', $field2='$data22[$l]', $field3='$data32[$l]',$field4='$dataname42[$l]'";
$result = mysql_query($query) or die(mysql_error());
++$l;
echo "<br> cnnt's value: ".$cnnt."<br>";
}
now I have looked at how the data is being processed and it is just totally killing me. I hope that someone can help me out.
here is what it returns if it helps. just one string.
SEX,Frequency,Percent,ValidPercent,CumulativePercent,Valid,F,627,60.5,60.5,60.5,M,409,39.4,39.4,99.9,uk,1,.1,.1,100.0,Total,1037,100.0,100.0,
instances count line:25
instances count -5:20
instances of floor /5:4
location of star str:58
stars new position:79
cnt's value:79
stars new position:100
cnt's value:100
stars new position:117
cnt's value:117
stars new position:
cnt's value:
SEX table successfully created!
Data count:
array(4) { [0]=> string(3) "627" [1]=> string(3) "409" [2]=> string(1) "1" [3]=> string(4) "1037" }
INSERT INTO SEX
SET dataset =F
Frequency=627
Percent=60.5
ValidPercent=60.5
CumulativePercent=79
cnnt's value: 4
INSERT INTO SEX
SET dataset =M
Frequency=409
Percent=39.4
ValidPercent=39.4
CumulativePercent=100
cnnt's value: 4
INSERT INTO SEX
SET dataset =uk
Frequency=1
Percent=.1
ValidPercent=.1
CumulativePercent=117
cnnt's value: 4
INSERT INTO SEX
SET dataset =Total
Frequency=1037
Percent=100.0
ValidPercent=100.0
CumulativePercent=
cnnt's value: 4
I will post my code in another post 🙂
If you can spot anything that would be screwing up my data, or such let me know please, and if you see anything that may be wrong, or a better way to do something. I would be forever greatful.
This is not a hard script, its just that I have been staring at it for days, and for some reasone everything starts to blend together and... well im sure you can relate.
Thanks for any help,
-=Levi=-