followInTo Posted March 16, 2007 Share Posted March 16, 2007 This is reading a txt base database The code works outside a function but not inside. I'm not sure why, if someone can help alter the coding or tell me an answer, that'd be great! function getTheStuff($usname) { //Begin Pre coding if ($handle = opendir('db/us/')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $file = eregi_replace(".php", "", $file); $file = array($file); foreach($file as $listed) { $item3 = file("db/us/".$listed.".php"); foreach ($item3 as $item4) { list($rusername,$rpassword,$rpoints) = explode ("|^|", $item4); } // put all members into an array $allmembers[] = $rpoints."|^|".$rusername."|^|x|^|"; } } } closedir($handle); } // Begin to return data asort($allmembers); $count = 0; foreach($allmembers as $item) { ++$count; list($pointsxx,$usernamexx) = explode("|^|",$item); if($usernamexx == $usname) { return $count; } } } Quote Link to comment https://forums.phpfreaks.com/topic/43062-this-code-wont-work-in-a-function/ Share on other sites More sharing options...
Trium918 Posted March 16, 2007 Share Posted March 16, 2007 Try using global variables. Quote Link to comment https://forums.phpfreaks.com/topic/43062-this-code-wont-work-in-a-function/#findComment-209175 Share on other sites More sharing options...
followInTo Posted March 16, 2007 Author Share Posted March 16, 2007 could u help me redo that code i'm a little noobie at php Quote Link to comment https://forums.phpfreaks.com/topic/43062-this-code-wont-work-in-a-function/#findComment-209176 Share on other sites More sharing options...
followInTo Posted March 16, 2007 Author Share Posted March 16, 2007 the code doesnt work outside a function either, can someone just redo this thing please? Quote Link to comment https://forums.phpfreaks.com/topic/43062-this-code-wont-work-in-a-function/#findComment-209189 Share on other sites More sharing options...
Psycho Posted March 16, 2007 Share Posted March 16, 2007 The code works outside a function but not inside[ the code doesnt work outside a function either Does it or doesn't it. If it doesn't work at all what problems or errors are you experincing? Quote Link to comment https://forums.phpfreaks.com/topic/43062-this-code-wont-work-in-a-function/#findComment-209194 Share on other sites More sharing options...
followInTo Posted March 16, 2007 Author Share Posted March 16, 2007 it just doesnt work but no PHP Error comes up. something with the variable i think. Their not recording or something. Quote Link to comment https://forums.phpfreaks.com/topic/43062-this-code-wont-work-in-a-function/#findComment-209196 Share on other sites More sharing options...
Barand Posted March 17, 2007 Share Posted March 17, 2007 Code that doesn't work doesn't tell us what you are trying to do. What are you trying to achieve? Quote Link to comment https://forums.phpfreaks.com/topic/43062-this-code-wont-work-in-a-function/#findComment-209199 Share on other sites More sharing options...
kenrbnsn Posted March 17, 2007 Share Posted March 17, 2007 You keep on reusing the variable '$file'. Ken Quote Link to comment https://forums.phpfreaks.com/topic/43062-this-code-wont-work-in-a-function/#findComment-209200 Share on other sites More sharing options...
followInTo Posted March 17, 2007 Author Share Posted March 17, 2007 its just overriding the previous one, anyways i alrdy checked, that doesnt seem to be the problem It can read the directory just perfect but cannot put them in the array, i dont know why Quote Link to comment https://forums.phpfreaks.com/topic/43062-this-code-wont-work-in-a-function/#findComment-209203 Share on other sites More sharing options...
kenrbnsn Posted March 17, 2007 Share Posted March 17, 2007 Please explain what you think this function is supposed to do. Have you tried putting in "debug" statements that echo your data as it's being manipulated? Ken Quote Link to comment https://forums.phpfreaks.com/topic/43062-this-code-wont-work-in-a-function/#findComment-209241 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.