in reply to Re: Database question: pulling a particular field from a flat database
in thread Database question: pulling a particular field from a flat database

Sorry I didn't include the db example:
ID|Category|Name|Image|Description|Price|Taxable|thumb|Listing
Currently, the first part of the script, shown below, only looks for the first field in the database, or in this case the "ID" field. I want it instead to use the Listing field.
open DATA,$data; $line=<DATA>; @fields=split('\|',substr($line,0,index($line,";"))); %data=(); while (<DATA>) { my(@flds)=@fields; shift(@flds); my(@temp)=split('\|',substr($_,0,index($_,";"))); my($id)=shift(@temp); while ($#flds>-1) { if ($temp[0] eq "no") { $temp[0]=""; } $data{$id}{shift(@flds)}=shift(@temp); } } close DATA;
Thanks

Replies are listed 'Best First'.
Re: Re: Re: Database question: pulling a particular field from a flat database
by monkfish (Pilgrim) on Sep 05, 2001 at 19:02 UTC
    Do you want the id (by which you reference things later on in the script) to be the listing? If that is really the case then just change:

    my($id)=shift(@temp);

    to

    my($id)=$temp[7];

    This however may have other unwanted results in the code since @temp will now have one more element than it did before (since you didn't shift any thing off). You could change all of your shifts to pops and that should do what you want.

    If, however, what you are really concerned with is a display issue in the template below, then you'll want to do something like using: $data{$id}{'Listing'} in the display and leave the code alone.

    Does that help?

    -monkfish (the fishy monk)

      Thank you Monkfish! That did the trick!