Re: [PHP] grabbing variable from bottom to top
On Aug 3, 2003, Micah Montoy claimed that: |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 You could use some dHTML. At the top of the page, you would print something like p ID=CountingIDCalculating count./p Then, after the computing, SCRIPT LANGUAGE=JavaScript document.all(MyID1).innerText = 'Total Count: $count.'; /SCRIPT This code is probably very browser dependant, so YMMV. Jeff -- Registered Linux user #304026. lynx -source http://jharris.rallycentral.us/jharris.asc | gpg --import Key fingerprint = 52FC 20BD 025A 8C13 5FC6 68C6 9CF9 46C2 B089 0FED Responses to this message should conform to RFC 1855. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] grabbing variable from bottom to top
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] grabbing variable from bottom to top
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] grabbing variable from bottom to top
Ok, this is completely off the top of my head, and there is more than likely a better way, but if you HAVE to do this, then I guess here's an option: 1. turn on ob (output buffering at the top of the script 2. where you want the counter to be, echo something unique like [EMAIL PROTECTED]@ 3. once the script has ended flush the contents of OB into a variable like $obContents 4. do a str_replace('[EMAIL PROTECTED]@',$yourCounterValue, $obContents) 5. echo the $obContents to the screen I think a smarter way would be to re-organise your code somehow so that it does what you want, but maybe that can't be done (no way to know without seeing the code). Good luck, Justin French On Monday, August 4, 2003, at 01:04 PM, 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php