Hi again,
Again, I'm not sure if this is possible, but someone may be able to tell me one way or the other. If it is, I'd appreciate it if someone could give me a hand with the routines.
This is for a shopping cart, and these routines would be for reading and writing the data files. To write the data file, the only required input will be a product code ($pid). As well as that, there will be other optional fields such as size and colour. I want to have the options unlimited, meaning there can be none, or however many attributes the product needs.
The format for the data file would be (This is what would be printed to the data file for the *first* product):
$pid|$url|$name|$price # Basic product data, read from the database using the $pid (Product ID).
option1 = value #
option2 = value # There could be many options, or none at all.
~ # End the item.
Each additional item that is added to the cart will print only the final tilde (~) so the script will know that everything between the item separators will be one product, in the same way Matt's random text script works.
I'll use something like the query routine from dbMan to get the rest of the data from $pid before I write, so I can probably do the pipe-delimited bit myself, but I'm not sure how to write the options. Since I don't know the options and number of them (if any) until I get the form input, how do I get it to add the *other* variables from the form input to the data file? ie. foreach $othervariable print $name=$value. And how do I get the *actual* name of the variable as a text string to print so I'll be able to read it out again? For example, the input will be $colour=$value and I'll want to print that as "Colour=Red" (i.e. capitalise the first letter of the variable name), so I can read it back out again. Or is there a better way of doing it?
As to reading it, I really don't have a notion. I can probably get as far as putting the contents of each item into a variable, but I don't know how to separate out the pipe-delimited product data and the options??? I'll also need to be able to do this to modify quantities in the cart.
One more thing. There will be several databases that I want to read from, identifiable from the product code ($pid), which will be in the format "productdb-product". Is there a simple regular expression to separate the first part (product id, before the hyphen) out so I can read from the right database?
Any help with this will be much appreciated. I can probably figure out most of the rest of the stuff, but these routines and the cart id routines I've asked about in another thread are the only major stumbling blocks I think I'll have.
Thanks in advance,
adam
[This message has been edited by dahamsta (edited March 30, 1999).]
Again, I'm not sure if this is possible, but someone may be able to tell me one way or the other. If it is, I'd appreciate it if someone could give me a hand with the routines.
This is for a shopping cart, and these routines would be for reading and writing the data files. To write the data file, the only required input will be a product code ($pid). As well as that, there will be other optional fields such as size and colour. I want to have the options unlimited, meaning there can be none, or however many attributes the product needs.
The format for the data file would be (This is what would be printed to the data file for the *first* product):
Code:
~ # Start this item. $pid|$url|$name|$price # Basic product data, read from the database using the $pid (Product ID).
option1 = value #
option2 = value # There could be many options, or none at all.
~ # End the item.
Each additional item that is added to the cart will print only the final tilde (~) so the script will know that everything between the item separators will be one product, in the same way Matt's random text script works.
I'll use something like the query routine from dbMan to get the rest of the data from $pid before I write, so I can probably do the pipe-delimited bit myself, but I'm not sure how to write the options. Since I don't know the options and number of them (if any) until I get the form input, how do I get it to add the *other* variables from the form input to the data file? ie. foreach $othervariable print $name=$value. And how do I get the *actual* name of the variable as a text string to print so I'll be able to read it out again? For example, the input will be $colour=$value and I'll want to print that as "Colour=Red" (i.e. capitalise the first letter of the variable name), so I can read it back out again. Or is there a better way of doing it?
As to reading it, I really don't have a notion. I can probably get as far as putting the contents of each item into a variable, but I don't know how to separate out the pipe-delimited product data and the options??? I'll also need to be able to do this to modify quantities in the cart.
One more thing. There will be several databases that I want to read from, identifiable from the product code ($pid), which will be in the format "productdb-product". Is there a simple regular expression to separate the first part (product id, before the hyphen) out so I can read from the right database?
Any help with this will be much appreciated. I can probably figure out most of the rest of the stuff, but these routines and the cart id routines I've asked about in another thread are the only major stumbling blocks I think I'll have.
Thanks in advance,
adam
[This message has been edited by dahamsta (edited March 30, 1999).]