carric has asked for the wisdom of the Perl Monks concerning the following question:
I have been working on the logic for this and after looking through the DBI docs, the Perl DBI book, and numerous threads, nodes and posts I am still stumped.
I have a db with records with say 40 pieces of data, if which I only want 3 fields per record. The id itself and two other pieces of data based on whether or not some bit is set, e.g.:
SELECT extracted_ads_id, prop_street_no, prop_street_name FROM extracted_ads_tbl WHERE pin-on-off=0
The WHERE statement is just something I set to 1 later when I have manipulated the data. I need to be able to access prop_street_no and prop_street_name to use as vars for a spider that populates an http request to a search engine to extract another piece of data..
I would LIKE to build a hash of arrays (I think) where the key is the "extracted_ads_id" and the value is an array reference of prop_street_no and prop_street_name. I would then like to build another hash that has the extracted_ads_id with the subsequent PIN referenced in the SQL statement above, so I can then insert extracted_ads_id and pin into a seperate table.
INSERT INTO enhanced_ads_tbl (enhanced_ad_id,extracted_ads_id,pin) VALUES (NULL,?,?)
I am not sure which function I need to use from the DBI docs to achieve this (fetchrow_array(), fetchrow_arrayref(), etc.), or if that is even on the right track.
Thanks again for the help!!
####UPDATE###
Just in case ne1 else was trying to figure this out the first time... here is what I ended up doing:
....snip.... my $query1 = "SELECT field1,field2,field3 FROM table WHERE `flag`=0"; my $sth = $dbh->prepare($query1); $sth->execute(); # Loop query to build an array # this pulls each row into an # array that we can manipulate while ( ($var1,$var2,$var3) = $sth->fetchrow_array() ) { # update the flag field to reflect the ad has been ehnanced my $query2 = "UPDATE table SET `flag`='1' WHERE field1=?"; my $sth2 = $dbh->prepare($query2); $sth2->execute($var1); ....snip.... }
So what this does for me: query a table, load the returned values into an array, that I can then use as values I iterate through when updating a field in the db, or access each successive row returned as an array of values for variables... what I was doing with this was pulling an id, and the number and street name from a table of addresses, so I could use these values to pass in a URL for spidering some info off a site.. I could iterate through my db of addresses by $street_no, $street_name and push the returned results into anther table this way. It's yummy. =)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl MySQL Table into an array
by pbeckingham (Parson) on Mar 13, 2004 at 21:47 UTC | |
by carric (Beadle) on Mar 14, 2004 at 01:48 UTC | |
|
Re: Perl MySQL Table into an array
by tachyon (Chancellor) on Mar 13, 2004 at 22:34 UTC | |
by carric (Beadle) on Mar 14, 2004 at 02:23 UTC | |
|
Re: Perl MySQL Table into an array
by simonm (Vicar) on Mar 13, 2004 at 22:47 UTC |