align-toparrow-leftarrow-rightbackbellblockcalendarcamerachatcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-crosscrosseditfacebookglobegoogleimagesinstagramlocation-pinmagnifying-glassmailmoremuplabelShape 3 + Rectangle 1outlookpersonplusImported LayersImported LayersImported Layersshieldstartwitteryahoo

Milwaukee PHP Users Group Message Board MKEPUG Discussion Forum › Noob in need of some guidance?

Noob in need of some guidance?

whispers007
whispers007
Oak Creek, WI
Post #: 8
HI..thanks for sticking with me.. LOL

I have a bit of progress..

I am going to try your PRINT vs ECHO suggestion right.....now.

//echo($allRecords);
print_r($allRecords);

(didnt work).... still got this output...


('','Array[1]','Array[2]','Array[3]','­','','Array[4]','Array[5]','Array[6]','A­rray[7]','Array[8]','Array[9]','Array[10­]','Array[11]','Array[12]','Array[13]','­Array[14]','Array[15]','Array[16]','Arra­y[17]','Array[18]','Array[19]','Array[20­]','Array[51]','Array[52]','Array[53]','­Array[54]','Array[55]','Array[56]','Arra­y[57]','Array[58]','Array[59]','Array[60­]','Array[61]','Array[62]','Array[63]','­Array[64]','Array[65]','Array[66]','Arra­y[67]','Array[140]','Array[141]','Array[­142]','Array[143]','Array[144]','Array[1­45]','Array[146]','Array[147]','Array[14­8]','Array[149]','Array[150]','Array[151­]','Array[152]','Array[153]','Array[154]­','Array[155]','Array[156]','Array[157]'­,'Array[158]','Array[159]','Array[160]',­'Array[161]','Array[162]','Array[163]','­Array[164]','Array[165]','Array[166]','A­rray[167]','Array[168]','Array[169]','Ar­ray[170]','Array[171]','Array[172]','Arr­ay[173]','Array[174]','Array[175]','Arra­y[176]','Array[177]','Array[178]','Array­[179]','Array[180]','Array[181]','Array[­182]','Array[183]','Array[184]','Array[1­85]','Array[186]','Array[187]','Array[18­8]','Array[189]','Array[190]','Array[191­]','Array[192]','Array[193]','Array[194]­','Array[195]','Array[196]','Array[197]'­,'Array[198]','Array[199]','Array[200]',­'Array[201]','Array[202]','Array[203]','­Array[204]','Array[205]'), ('','Array[1]','Array[2]','Array[3]','',­'','Array[4]','Array[5]','Array[6]'.....­.etc...etc...etc..)

I am 'adding to the $allRecordsArray on each loop.. so I can do 1 INSERT on many records...

moving on.. I tried to break up the STRING.. like this.. and am now getting 'data' in the echo/print out.. BUT am NOT getting anything into the database.. and NOT getting any errors to help direct me?


//** first index is ID# (auto-populated)
$allRecords .= "('','" . $allLinesArray[$i][1] . "' ,'" . $allLinesArray[$i][2] . "' ,'" . $allLinesArray[$i][3] . "' ,'First Name Holder','Middle Name Holder','" . $allLinesArray[$i][4] . "' ,'" . $allLinesArray[$i][5] . "' ,'" . $allLinesArray[$i][6] . "' ,'" . $allLinesArray[$i][7] . "' ,'" . $allLinesArray[$i][8] . "' ,'" . $allLinesArray[$i][9] . "' ,'" . $allLinesArray[$i][10] . "' ,'" . $allLinesArray[$i][11] . "' ,'" . $allLinesArray[$i][12] . "' ,'" . $allLinesArray[$i][13] . "' ,'" . $allLinesArray[$i][14] . "' ,'" . $allLinesArray[$i][15] . "' ,'" . $allLinesArray[$i][16] . "' ,'" . $allLinesArray[$i][17] . "' ,'" . $allLinesArray[$i][18] . "' ,'" . $allLinesArray[$i][19] . "' ,'" . $allLinesArray[$i][20] . "' ,'" . $allLinesArray[$i][51] . "' ,'" . $allLinesArray[$i][52] . "' ,'" . $allLinesArray[$i][53] . "' ,'" . $allLinesArray[$i][54] . "' ,'" . $allLinesArray[$i][55] . "' ,'" . $allLinesArray[$i][56] . "' ,'" . $allLinesArray[$i][57] . "' ,'" . $allLinesArray[$i][58] . "' ,'" . $allLinesArray[$i][59] . "' ,'" . $allLinesArray[$i][60] . "' ,'" . $allLinesArray[$i][61] . "' ,'" . $allLinesArray[$i][62] . "' ,'" . $allLinesArray[$i][63] . "' ,'" . $allLinesArray[$i][64] . "' ,'" . $allLinesArray[$i][65] . "' ,'" . $allLinesArray[$i][66] . "' ,'" . $allLinesArray[$i][67] . "' ,'" . $allLinesArray[$i][140] . "' ,'" . $allLinesArray[$i][141] . "' ,'" . $allLinesArray[$i][142] . "' ,'" . $allLinesArray[$i][143] . "' ,'" . $allLinesArray[$i][144] . "' ,'" . $allLinesArray[$i][145] . "' ,'" . $allLinesArray[$i][146] . "' ,'" . $allLinesArray[$i][147] . "' ,'" . $allLinesArray[$i][148] . "' ,'" . $allLinesArray[$i][149] . "' ,'" . $allLinesArray[$i][150] . "' ,'" . $allLinesArray[$i][151] . "' ,'" . $allLinesArray[$i][152] . "' ,'" . $allLinesArray[$i][153] . "' ,'" . $allLinesArray[$i][154] . "' ,'" . $allLinesArray[$i][155] . "' ,'" . $allLinesArray[$i][156] . "' ,'" . $allLinesArray[$i][157] . "' ,'" . $allLinesArray[$i][158] . "' ,'" . $allLinesArray[$i][159] . "' ,'" . $allLinesArray[$i][160] . "' ,'" . $allLinesArray[$i][161] . "' ,'" . $allLinesArray[$i][162] . "' ,'" . $allLinesArray[$i][163] . "' ,'" . $allLinesArray[$i][164] . "' ,'" . $allLinesArray[$i][165] . "' ,'" . $allLinesArray[$i][166] . "' ,'" . $allLinesArray[$i][167] . "' ,'" . $allLinesArray[$i][168] . "' ,'" . $allLinesArray[$i][169] . "' ,'" . $allLinesArray[$i][170] . "' ,'" . $allLinesArray[$i][171] . "' ,'" . $allLinesArray[$i][172] . "' ,'" . $allLinesArray[$i][173] . "' ,'" . $allLinesArray[$i][174] . "' ,'" . $allLinesArray[$i][175] . "' ,'" . $allLinesArray[$i][176] . "' ,'" . $allLinesArray[$i][177] . "' ,'" . $allLinesArray[$i][178] . "' ,'" . $allLinesArray[$i][179] . "' ,'" . $allLinesArray[$i][180] . "' ,'" . $allLinesArray[$i][181] . "' ,'" . $allLinesArray[$i][182] . "' ,'" . $allLinesArray[$i][183] . "' ,'" . $allLinesArray[$i][184] . "' ,'" . $allLinesArray[$i][185] . "' ,'" . $allLinesArray[$i][186] . "' ,'" . $allLinesArray[$i][187] . "' ,'" . $allLinesArray[$i][188] . "' ,'" . $allLinesArray[$i][189] . "' ,'" . $allLinesArray[$i][190] . "' ,'" . $allLinesArray[$i][191] . "' ,'" . $allLinesArray[$i][192] . "' ,'" . $allLinesArray[$i][193] . "' ,'" . $allLinesArray[$i][194] . "' ,'" . $allLinesArray[$i][195] . "' ,'" . $allLinesArray[$i][196] . "' ,'" . $allLinesArray[$i][197] . "' ,'" . $allLinesArray[$i][198] . "' ,'" . $allLinesArray[$i][199] . "' ,'" . $allLinesArray[$i][200] . "' ,'" . $allLinesArray[$i][201] . "' ,'" . $allLinesArray[$i][202] . "' ,'" . $allLinesArray[$i][203] . "' ,'" . $allLinesArray[$i][204] . "' ,'" . $allLinesArray[$i][205] . "')";



Beth Tucker L.
e3betht
Verona, WI
Post #: 36
If that is what print_r() is displaying, then that is all that's in $allRecords. Where do you create $allRecords? This may go faster if we take this offline and you email me: beth@musketeers.me or I'll try to check this more often than once a day when I get the Meetup notifications. :)
whispers007
whispers007
Oak Creek, WI
Post #: 9
YIKES!..

seems some at least 1 (maybe 2?) of my posts didnt make it? LOL..

anyways..

thanks Beth...

for 'now' I think I go tit all sorted out.. had some column name error(s) I need to fix as well..

and for 'now' I think it works.. 'ok'

*could probably use some better 'error' checking to handle missing data.. or mal-formatted data.. (but I'll have to look up the best ways to handle that stuff I guess)... :)

such as one of the 'name' fields.. sometimes does NOT have a comma to separate the data.. so I get an error/warning/notice about an 'off-set'..?

everything still seems to be INSERTing into the db ok though..

my final script ended up being this:



*followed in next post.. because this exceed character length.



my next step is to take a 'list' of numbers.. (quite a large list..10's of thousands)..

and do a 'query' against the DB using each number in this list as the search term.. once found.. return another piece of data/item in another column in that matching record/row..

what is the best (general approach)?

1.) scrape directory for .text file to be used to get my source data from.. (source file)
2.) parse data from the source file and create my 'master list' (array) of search number..
3.) using this 'master list' array.. loop through it.. and query the DB using the masterList[$i] index value as my search term and return the data back another array?

Is the DB 'return' fast enough to loop through this array? or is there some sort of 'pause/delay' I need to do to wait for the a 'return'..and then move onto te next iteration in my loop?

thanks!
whispers007
whispers007
Oak Creek, WI
Post #: 10
still walking through this.. :)

Im not really sure how to handle the RETURNED data when using a WHEN IN type query..

here is what I trying currently..


$harNumArray2 = implode(',', $harNumArray);
//$harNumArray2 = '"' . implode('","', $harNumArray) . '"';

//no work
$result = mysql_query("SELECT har_id, guar_num FROM placements WHERE har_id IN (" . $harNumArray2 . ")")
//works
//$result = mysql_query("SELECT har_id, guar_num FROM placements WHERE har_id IN (0108383442,0106620416)")
or die(mysql_error());

// store the record of the "example" table into $row
$row = mysql_fetch_array($result);
$numRows = mysql_num_rows($result);

// Print out the contents of the entry
echo("<BR>");
echo("TOTAL ROWS RETURNED : " . $numRows . "<BR>");
echo "HAR ID: ".$row['har_id'];
echo " GUAR ID: ".$row['guar_num'];



obviously something isnt right here...

because I dont get a 'list' printed out.. only the LAST instance of the loop/last record data...


Im not clear on how the data is returned I guess?

is $rows the data in array format then?

if I print out $rows[0]/$rows[1] I get data... and it seems to be the same LAST piece of the data in the match/record set.

in the example above.. there is a controlled 5 records Im working with in the text file..

this code:

$harNumArray2 = implode(',', $harNumArray);
//$harNumArray2 = '"' . implode('","', $harNumArray) . '"';
//$query = "'SELECT guar_num FROM placements WHERE har_id IN ($harNumArray2)'";
print_r("ARRAY CHECK: " . $harNumArray2);
echo("<BR>");
echo("<BR>");

$result = mysql_query("SELECT har_id, guar_num FROM placements WHERE har_id IN (" . $harNumArray2 . ")") or die(mysql_error());
print_r("QUERY CHECK: " . $result);
echo("<BR>");
echo("<BR>");
print_r("QUERY CHECK 2: " . "SELECT har_id, guar_num FROM placements WHERE har_id IN (" . $harNumArray2 . ")");
echo("<BR>");
echo("<BR>");
//$result = mysql_query("SELECT har_id, guar_num FROM placements WHERE har_id IN (0108383442,0106620416)")


// store the record of the "example" table into $row
$row = mysql_fetch_array($result);
$numRows = mysql_num_rows($result);


echo("ROW CHECK: " . $row[0]);
echo("<BR>");
echo("ROW CHECK: " . $row[1]);
echo("<BR>");


// Print out the contents of the entry
echo("<BR>");
echo("<BR>");
echo("TOTAL ROWS RETURNED : " . $numRows . "<BR>");
echo "HAR ID: ".$row['har_id'];
echo " GUAR ID: ".$row['guar_num']

gives this results on screen:


Array ( [0] => sample_source.txt )

Total FILES TO GRAB HAR ID's FROM: 1

TOAL HARS FOUND IN ALL FILES: 5
ARRAY CHECK: 108383442,106620416,109570835,109700427,­100022236

QUERY CHECK: Resource id #7

QUERY CHECK 2: SELECT har_id, guar_num FROM placements WHERE har_id IN (108383442,106620416,109570835,109700427­,100022236)

ROW CHECK: 000100022236
ROW CHECK: 0000717083


TOTAL ROWS RETURNED : 5
HAR ID: 000100022236 GUAR ID: 0000717083

which all seems 'right/correct'.... except I am only getting 1 'pair' printed to the screen..... and not a 'list' of all 5 pairs/matches...

make sense? :)

Maybe I need to lop through an array or object? but doest seem like the $row array is a 'full' array?

only holding the last returned data..

thanks
Powered by mvnForum

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy