alby Posted May 25, 2007 Share Posted May 25, 2007 Hi, I've come across a situation today thats confusing the hell out of me if(isset($GLOBALS["_GET"])){ while(list($key, $val) = each($GLOBALS["_GET"])) { //echo "test ".$key." ".$val." "; $key = stripslashes($key); $val = stripslashes($val); $key = urlencode($key); $val = urlencode($val); $getString .= "$key=$val&"; } } if(!is_array($inQuery)){ // if it's a MySQL query //get db records $conn = db_connect(); $outputResult = $conn->query($inQuery); //the result object result $outputCount = $outputResult->num_rows; //the result object resultCount $outputResult->free_result(); $conn->close(); } else { // if it's an array $outputCount = count($inQuery); // Count the number of elements in the array } echo "1 ".$getString; //dont do anything else if there arent enough records to warrant prev/next if ($outputCount <= $limit){ $this->navDump = ""; $this->outQuery = $inQuery; return; } echo "2 ".$getString; The variable $getString, is created by the first part of the script. An example of the output for this is "sMethod=music&sText=thunder&x=9&y=6" and this works fine. The problem has appeared today when sText was 60s making the string "sMethod=music&sText=60s&x=9&y=6" Echo 1 displays it fine however after the "return;" command it wipes the variable so echo 2 will not print it. I've tried a few different variations and it seems when sText has a number in it return; wipes the variable. Any ideas would be greatly appreciated as its got me completely stumped. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/52951-v-v-confused/ Share on other sites More sharing options...
obsidian Posted May 25, 2007 Share Posted May 25, 2007 As soon as you call return from within a function, processing of that function code ceases. So, as soon as you hit the "return" line, nothing beyond would be processed. That would be why the second is not echoing. Quote Link to comment https://forums.phpfreaks.com/topic/52951-v-v-confused/#findComment-261532 Share on other sites More sharing options...
alby Posted May 25, 2007 Author Share Posted May 25, 2007 Hi, Its not that the echo is not calling as the IF statement is not entered and it prints out the number 2, and the rest of the script after that is fine, it just clears the $getString variable. I know its the "return;" causing the problem as it works fine if I comment it out. Quote Link to comment https://forums.phpfreaks.com/topic/52951-v-v-confused/#findComment-261535 Share on other sites More sharing options...
obsidian Posted May 25, 2007 Share Posted May 25, 2007 So, what is the return supposed to be doing? You're not returning a value with it. Quote Link to comment https://forums.phpfreaks.com/topic/52951-v-v-confused/#findComment-261536 Share on other sites More sharing options...
alby Posted May 25, 2007 Author Share Posted May 25, 2007 This is only part of the script. The function is designed to take a query or array along with a limit and offset and output it only displaying the required results. It also outputs a navigation bar (i.e. prev 1234 next). That IF statement is only called if there isn't enough records to warrant a nav bar so it ends the function. On this occasion there is enough records for a nav bar so that IF statement isn't called. The part that is confusing me is that this script has worked fine for months until recently when someone entered 60s as the sText and because $getString cleared, the navigation doesnt work properly as these are the GET's added to the end of each link. Quote Link to comment https://forums.phpfreaks.com/topic/52951-v-v-confused/#findComment-261538 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.