Jump to content

[SOLVED] Variable value problem


ishkur

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/67818-solved-variable-value-problem/
Share on other sites

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' 
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.