ishkur Posted September 3, 2007 Share Posted September 3, 2007 Ok, so i'm having this problem: I have a function who receives 16 arguments and has to process them into a sql query string. No problem there. Problem is that one of the arguments, i have NO idea why, is inserted into the string as a Null value... function My_Func ($inf_1, $inf_2, $inf_3 (...), $inf_16) { echo $inf_12; $sql_b = "'".$inf_1."'".", "; $sql_b .= "'".$inf_2."'".", "; $sql_b .= "'".$inf_3."'".", "; (...) $sql_b .= "'".$inf_11."'".", "; $sql_b .= "'".$inf_12."'".", "; $sql_b .= "'".$inf_13."'".", "; $sql_b .= "'".$inf_14."'".", "; $sql_b .= "'".$inf_15."'".", "; $sql_b .= "'".$inf_16."'".", "; } This is a cut-down and adapted version of the function, just to show the problem. In the "echo" instruction i inserted for verification after geting the null insertion, the variable value is printed correctly. But in the "string insertion" it is put as a null value... If i passed integers 1-16 as arguments, $sql_b would consist of: " '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '', '13', '14', '15', '16' " For the life of me, i can't figure out why... Any help ideas? Quote Link to comment https://forums.phpfreaks.com/topic/67818-solved-variable-value-problem/ Share on other sites More sharing options...
Barand Posted September 3, 2007 Share Posted September 3, 2007 it would be easier to pass an array with 16 elements <?php function myfunc ($arr ) { return "'" . join ("','", $arr) . "'"; } $array = array(); for ($i=1; $i<=16; $i++) { $array[] = $i; } echo myfunc($array); // --> '1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16' ?> Quote Link to comment https://forums.phpfreaks.com/topic/67818-solved-variable-value-problem/#findComment-340854 Share on other sites More sharing options...
ishkur Posted September 3, 2007 Author Share Posted September 3, 2007 Converted the function to receive array values, still same problem ??? EDIT: tried using "join" instead of editing string for each value, still same problem... ??? Quote Link to comment https://forums.phpfreaks.com/topic/67818-solved-variable-value-problem/#findComment-340867 Share on other sites More sharing options...
pocobueno1388 Posted September 3, 2007 Share Posted September 3, 2007 Post your array, then your function. Quote Link to comment https://forums.phpfreaks.com/topic/67818-solved-variable-value-problem/#findComment-340871 Share on other sites More sharing options...
Ken2k7 Posted September 3, 2007 Share Posted September 3, 2007 Then something's wrong with "$inf_12." I would check that out and make sure it has a value. Quote Link to comment https://forums.phpfreaks.com/topic/67818-solved-variable-value-problem/#findComment-340872 Share on other sites More sharing options...
Barand Posted September 3, 2007 Share Posted September 3, 2007 what does this give var_dump($inf_12); Quote Link to comment https://forums.phpfreaks.com/topic/67818-solved-variable-value-problem/#findComment-340876 Share on other sites More sharing options...
ishkur Posted September 3, 2007 Author Share Posted September 3, 2007 Rewrote code from scratch using all advice, solved problem. I think it was a problem of variable scope, but not sure. Anyway, array code is better than as i was doing it, and all is working. Thanks a lot Quote Link to comment https://forums.phpfreaks.com/topic/67818-solved-variable-value-problem/#findComment-340889 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.