i'm writing again because i'm still really lost-- and i should be more far along on the whole thing, but i really want to figure out this whole stinkin Excel conversion thing or i'm not going to be satisfied!
the first time i tried sfullmans's offering, i didn't get anything from it because i was too fixated on trying to understand the functions therein, and how their purpose applied to my data-- but this time i disregarded those particulars and made a little script to get a better look at what those functions are actually doing in this arrangement, and what sfullman really intended for me to get from it.
here's my code.
FYI - the mysql_result() lines are inserted as part of an "extract MySQL row data" wizard in my preferred IDE, TSW WebCoder 2005 , which has several PHP/MySQL productivity enhancing options while it's connected to the MySQL server - an easy way for me to test sfullman's code w/out understaning what he wanted me to get from the query, so i took a stab at echoing the bus-stop codes to see what would happen:
$myfile = "../csv/H.csv";
$fp=fopen($myfile,'r'); //a legal csv file
while($r=fgetcsv($fp,100000)){
//we now have the row as array $r
$result = mysql_query("SELECT time_id, stop_code, rt01, rt02, rt03, rt04, rt05, rt06, rt07, rt08, rt09, rt10, rt11, rt12, rt13, rt14, rt15, rt16, rt17, rt18, rt19, rt20, rt21 FROM h_csv_test WHERE time_id = '".$r[0]."'"); //make sure it doesn't die
$time_id = mysql_result($result, 0, "time_id");
$stop_code = mysql_result($result, 0, "stop_code");
$rt01 = mysql_result($result, 0, "rt01");
$rt02 = mysql_result($result, 0, "rt02");
$rt03 = mysql_result($result, 0, "rt03");
$rt04 = mysql_result($result, 0, "rt04");
$rt05 = mysql_result($result, 0, "rt05");
$rt06 = mysql_result($result, 0, "rt06");
$rt07 = mysql_result($result, 0, "rt07");
$rt08 = mysql_result($result, 0, "rt08");
$rt09 = mysql_result($result, 0, "rt09");
$rt10 = mysql_result($result, 0, "rt10");
$rt11 = mysql_result($result, 0, "rt11");
$rt12 = mysql_result($result, 0, "rt12");
$rt13 = mysql_result($result, 0, "rt13");
$rt14 = mysql_result($result, 0, "rt14");
$rt15 = mysql_result($result, 0, "rt15");
$rt16 = mysql_result($result, 0, "rt16");
$rt17 = mysql_result($result, 0, "rt17");
$rt18 = mysql_result($result, 0, "rt18");
$rt19 = mysql_result($result, 0, "rt19");
$rt20 = mysql_result($result, 0, "rt20");
$rt21 = mysql_result($result, 0, "rt21");
if(mysql_num_rows($result)){
$rows = mysql_num_rows($result);
echo "<p>the stop code is ".$stop_code."</p>";
echo "<p>mysql num rows is".$rows."</p>";
//this requires an update statement, but you may want to check the createDate, update only partial data, etc.
}else{ echo $rt02;
//this requires an insert
}
}
(i realize now that the $rows is irrelevant, but rather than filter that, i just showed exactly what i did...)
and here's what i get as output from that:
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 5 in C:...\sfullman_orig.php on line 12
(one of those for lines 12 - 34, at which point it does echo: )
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 5 in C:\...\sfullman_orig.php on line 34
the stop code is h31
mysql num rows is1
the stop code is h32
mysql num rows is1
the stop code is h33
mysql num rows is1
the stop code is h34
mysql num rows is1
the stop code is h34a
mysql num rows is1
the stop code is h34b
mysql num rows is1
the stop code is hc131a
mysql num rows is1
the stop code is hc131b
mysql num rows is1
the stop code is h27
mysql num rows is1
the stop code is h28
mysql num rows is1
the stop code is h29
mysql num rows is1
the stop code is h30
mysql num rows is1
the stop code is h31
mysql num rows is1
the stop code is h32
mysql num rows is1
and one more series of the mysql_result warnings (which, btw, i realize i wouldn't get those if i were using a different method-- but i used the data extraction wizard to investigate sfullman's script, not for any preferred functionality necessarily)
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 20 in C:\...\sfullman_orig.php on line 34
the stop code is h34
mysql num rows is1
the stop code is h34b
mysql num rows is1
the stop code is hc131b
mysql num rows is1
the stop code is h28
mysql num rows is1
the stop code is h30
mysql num rows is1
so, i'm looking for ideas-- based on the screen shots i provided above, for how to tweak this so that i can get what i need from the CSV file and put it into my db.
what can i do to test if the CSV file data is even being read at all? or-- if this shows that it's being read, then how do i move on to the second step, which i think would be to figure out how make use of the raw csv data.
suggestions? help? thanks!
EDIT: i added this-- i think i'm on to something finally-- but i could still use help, advice, a knock in the head-- whatever you have for me 😉
if(mysql_num_rows($result)){
foreach($r as $csvdata) {
echo "the \$r=fgetcsv shows:".$csvdata."<br />";
}
which gives me:
the $r=fgetcsv shows:7:17
the $r=fgetcsv shows:7:18
the $r=fgetcsv shows:7:19
//snip...
the $r=fgetcsv shows:7:25
the $r=fgetcsv shows:7:27
the $r=fgetcsv shows:7:30
the stop code is h30
mysql num rows is1
which appears to be the ENTIRE csv contents (7:17 is AM, and 7:30 is PM, so the entire day is represented)... now i just have to figure out what to do here...