Page 1 of 1

Help with a script...

Posted: Wed Mar 12, 2008 9:50 am
by luigi193
I am building a simple price calculator for a client's client... I had found a way to figure everything else out and get it all working, except for one part.

Let me explain the idea of the project first: The user is suppose to enter a password, and depending on the password that is entered, read a certain text file with prices. I used the file() command, that brings in every line as a new part of the array, I then used array_unshift to make the first line be 1 instead of zero. There is an admin area, where they can change the prices in the text file... but I would really like line numbers. I want the actual file to look like this:
1)1234
2)2345

BUT when its called to be echoed into the table, have it strip out the "number)" part... I tried to do a loop that striped out the first part using str_replace, but that only worked for 1-10... I have to up to 98. Can anyone help me find a way to do this? This is my first time writing in PHP (or anything) and I hate asking for help, but I have been looking everywhere for a solution, and I can't get one to work! Any help would be appreciated.

Re: Help with a script...

Posted: Wed Mar 12, 2008 11:08 am
by andym01480
I'm not sure if I have understood your question! But here goes

Why not store the prices in the text file with a separate line for each price with no line numbers
When you grab the contents into an array say $prices, the array has a key which is a number starting at zero, which identifies which line in effect you are looking at. The line number is therefore the key+1. When you need to display line number 6 you look at $prices[5]

You can process the data without line numbers using the key as line number(-1).
In the admin area, to show line numbers you could do something like

Code: Select all

echo $linenumber.')'.$price[$linenumber-1];

Re: Help with a script...

Posted: Wed Mar 12, 2008 12:39 pm
by luigi193
OMG GENIUS. Instead of having the line numbers be in my Text file with the prices, just simply echo the line number on the admin page!!!!

OMG you don't know how long I wasted trying to do it the hard way....

Re: Help with a script...

Posted: Wed Mar 12, 2008 12:49 pm
by andym01480
Pleasures all mine. Glad to help... Less of the blasphemy though please!