Re: grabbing variable from bottom to top
| From: | Jason Sheets | Date: | Mon, 04 Aug 2003 04:21:11 +0000 |
| Subject: | Re: grabbing variable from bottom to top | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-158112@lists.php.net to get a copy of this message | ||
You can't get the intended value from a variable that hasn't been defined yet, obviously because you haven't given the variable a value. If you are trying to make something like a counter you may consider one of the following:
1. Insert the value into a database like MySQL or PostgreSQL,
2. Write the variable to a text file
3. Use PHP Sessions to store the variable between requests.
Of these choices #1 is generally the best choice, #2 will not deal with concurrent requests well and may corrupt the information, #3 will only work for a single visitor.
If the values are in an array you might use count($array) that will tell you the number of elements in the array, if the values are a delimited string you can use count(explode('seperator', 'data')) or something like that. The other thing you can do is run through the loop and instead of printing output put it into a variable, then at the end of the loop print the number, then print the variable containing the output, then print the end text.
Jason
Micah Montoy wrote:
Anyone know of a way to use a variable that isn't defined until further down the script at the top. I have a counter and once everything runs through the script, the count is complete, I need to display this at the top above the displayed results. I thought about and tried a function but I still run into the same problem. thanks