Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Building Databases with Hash, List, or Arrays???

Status
Not open for further replies.

jonthequik

Programmer
Aug 6, 2000
40
0
0
US
I'm trying to make a database to help me. I run a newspaper site with Classified Ads. Now, each week I spent fruitless hours updated some 25 different classified section some with the same ads. Now, I plan to have a database that will have an Ad Number, Section Number, Header, and the body of the ad....

1 108 Administrator We are currently....
2 113 Help Wanted FT/PT Positions Available...

Some of the body will be many lines long, I need to script to access the database and pull all ads with the same section number. I.E. if someone is parusing section 108, I need all 108 ads to be pulled. I think this can be done if I work at it, my problem is will it work better with Hash, as a list or as an Array!!!???

TIA for listening and offering advice.
 
Hello jonthequik,

Your post ends by asking "..will it work better with Hash, as a list or as an Array!!!???".
I think I would pull each row into an array. You know the order in which the elements will occur and you can dereference the items from their array positions easily. If we are talking about a reasonably small amount of data, I would store it in a pipe delimited flat file and simply pull/spit each row into its own array, maybe naming each array with the Ad number from that row in the file. That way you could read the file into a series of arrays, tweak the individual arrays (ads) you want changed and then write the entire data set back to disk.

You could also easily cycle through the arrays (ads) and check each section number ($array[1]) and return the ones that met your search criteria.

I hope this answers your question.




keep the rudder amid ship and beware the odd typo
 
If you need to have it all in one data structure, put it into a hash so that you can name each field.

But, I would suggest using an RDMS such as MySQL (a free linux database). Then you could simply request each field independently via SQL from the database. A far better solution! Then you wouldn't need to worry about data structures.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top