Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.