jfontestad Posted May 7, 2012 Share Posted May 7, 2012 Here's the situation and scenario. I am pulling variables from a text file and looping them through a function in order to get a result, problem is, that something is happening that is not allowing the results to pass through correctly. Weird thing is, that if there is only one variable present, the script works, if more than one variable is in the list, then that's where the problem comes in. The script only returns the correct result with the last variable in the list, all other variables seem to no be passing correctly. Here is the process: grab first line of text file use that variable to request data from an ssl site using fsock returns a result based on returned data from the post query loops back around to start over with next variable in list. I have tried everything that i could think of. I basically want the script to reset completely as if only one variable were submitted. I am suspecting that it has something to do with the foreach() function. Does it have anything to do with the session since its ssl? Like I said when only one variable is present in the text file, it works accordingly. When more than one variable, it only works correctly with the last variable. The other variables return the incorrect result. at the end of the file, i even manually unset every variable in the script to make sure that i starts with all variables undefined just in case and still... no dice. code that i am using can be viewed at http://fontestad.net/personal/jf/pt/t.phps thank you. Quote Link to comment https://forums.phpfreaks.com/topic/262225-what-is-being-done-wrong-problem-while-looping/ Share on other sites More sharing options...
MMDE Posted May 7, 2012 Share Posted May 7, 2012 Please give us the code you currently have, so it will be easier for us to help you. Post it using the code tags, thank you! Also, if you are having problems, try to debug the problem. What exactly is not working? Is it working with the data you think it is? Quote Link to comment https://forums.phpfreaks.com/topic/262225-what-is-being-done-wrong-problem-while-looping/#findComment-1343846 Share on other sites More sharing options...
jfontestad Posted May 8, 2012 Author Share Posted May 8, 2012 It is kind of working. It works with only the last variable in the list. For the rest of the variables it just gives back an incorrect results. I am suspecting that something is not passed correctly I posted code at the link above. Need I post it here as well? Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/262225-what-is-being-done-wrong-problem-while-looping/#findComment-1343930 Share on other sites More sharing options...
ManiacDan Posted May 8, 2012 Share Posted May 8, 2012 What do you believe this is supposed to do? onapi() will do the same thing every time. Quote Link to comment https://forums.phpfreaks.com/topic/262225-what-is-being-done-wrong-problem-while-looping/#findComment-1343950 Share on other sites More sharing options...
jfontestad Posted May 8, 2012 Author Share Posted May 8, 2012 i'm not that great at php, so my knowledge is limited. it seems as if it is nesting each variable. i just don't understand why it only returns the correct results for the last variable in the array. i'm thinking about changing the foreach loop to just a for loop and have it loop a specified number of times. Quote Link to comment https://forums.phpfreaks.com/topic/262225-what-is-being-done-wrong-problem-while-looping/#findComment-1343952 Share on other sites More sharing options...
jfontestad Posted May 8, 2012 Author Share Posted May 8, 2012 i'm thinking maybe just flush the buffer after each loop and then completely reset the script before the new loop begins Quote Link to comment https://forums.phpfreaks.com/topic/262225-what-is-being-done-wrong-problem-while-looping/#findComment-1343956 Share on other sites More sharing options...
ManiacDan Posted May 8, 2012 Share Posted May 8, 2012 What is "it." What are you expecting? What is the error? All we see is a script, we have no idea what your intentions are. function onapi() accepts zero arguments, and therefore your loop at the bottom of your script is useless, onapi() will do the same thing every time. What do you believe onapi() does? Quote Link to comment https://forums.phpfreaks.com/topic/262225-what-is-being-done-wrong-problem-while-looping/#findComment-1343968 Share on other sites More sharing options...
jfontestad Posted May 8, 2012 Author Share Posted May 8, 2012 onapi gets a variable (name) from a text file and submits it to the website (onapi.do), and depending on the result on the website (script searches for a specific string in the response), it will let me know if name is available or not. the result being, that it always tells me that all the name are available (which isn't true) with the exception of the last variable in the list (which it lets me know correctly if the name is available or not). so basically the script takes the first line from a text file, which is a product name, submits it to the website (onapi) and depending on the response the script lets me know if it is available or taken, then it moves on to the next name. Quote Link to comment https://forums.phpfreaks.com/topic/262225-what-is-being-done-wrong-problem-while-looping/#findComment-1343971 Share on other sites More sharing options...
jfontestad Posted May 8, 2012 Author Share Posted May 8, 2012 I figured it out. It's the way that the variables (names) were being read from the text file. Fixed it by using: $names = file('./t.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $names = array_map('rtrim',$names); Now everything works accordingly. Quote Link to comment https://forums.phpfreaks.com/topic/262225-what-is-being-done-wrong-problem-while-looping/#findComment-1343996 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.