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

It would have been helpful to include sample data, but from the code I conclude it looks like this:
fieldname1|fieldname2|fieldname3|fieldname4|fieldname5|fieldname6|fiel +dname7|fieldname8; Comment id1|val2|val3|val4|val5|val6|val7|val8; another comment no|val2b|val3b|val4b|val5b|val6b|val7b|val8b; another comment id1c|val2c|val3c|val4c|val5c|val6c|val7c|val8c; another comment

Is this correct?

The code is pulling all the fields. Rather than reference it by number, what is the name of the 8th field that you want?

-monkfish (the fishy monk)

  • Comment on Re: Database question: pulling a particular field from a flat database
  • Download Code

Replies are listed 'Best First'.
Re: Re: Database question: pulling a particular field from a flat database
by koacamper (Acolyte) on Sep 05, 2001 at 18:49 UTC
    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
      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!