Welcome Guest, Not a member yet? Register   Sign In
trying to create an array for XML-RPC = FAIL
#1

[eluser]skattabrain[/eluser]
I'm not creating my array to send of as an XML-RPC response correctly.

1 record ... this works ... but how do I use the foreach statement to add records into my array? I'm askign this way because everything I've tried FAILS. Also ... doing this Fails as well (I think it's because I'm using ODBC, not MySQL ...

return $this->xmlrpc->send_response($query->result_array());

Here's my function ... how would you go about looping it? Please don't tell me that $items is overwriting itself in each loop, I know this. I'm posting this here as is because it's the only way I can it going at all. I usually do soemthing below but XML-RPC rejects it ...

Code:
foreach($query->result() as $item)
{
$items[$item->someuniquestring_or_a_counter] =    
            array(              
                'CustomerNo' => array($qitem->CustomerNo,'string'),
                'CustomerName' => array($qitem->CustomerName,'string')
                );
}

I've tried array_push ... no dice.

This is day 2 of XML-RPC/ODBC HELL ... Please save me.

Code:
function test()
    {
        $query = $this->db->query("SELECT * FROM AR_Customer");
        
        $items = array();
        
        foreach($query->result() as $item)
        {
            $items =    
            array(              
                'CustomerNo' => array($item->CustomerNo,'string'),
                'CustomerName' => array($item->CustomerName,'string')
                );
        }
        
        $response = array($items, 'struct');

        return $this->xmlrpc->send_response($response);    
    }
#2

[eluser]Nick Husher[/eluser]
You aren't setting a data type for the collection of fields within the loop in the first example:

Code:
$items = array(array(
   'CustomerNo' => array($item->CustomerNo,'string'),
   'CustomerName' => array($item->CustomerName,'string'),
), 'struct');

Here's some code I whipped up a few minutes ago. It seems to work (I can query it with a CI XML-RPC client and it returns the data okay):

Code:
// I have an array of objects named $state, each object in the array
    //has a 'name' and 'shortname' property
    $state_array = array();

    foreach($states as $state) {
        $state_array[] = array(array(
                'name'=> array($state->name,'string'),
                'abbv'=> array($state->shortname,'string')
            ),'struct');
    }
    $response = array($state_array, 'array');
    return $this->xmlrpc->send_response($response);
#3

[eluser]skattabrain[/eluser]
Nick ... if you were female ... and 'eh ... hot ... and 'eh ... I wasn't married, I'd kiss you! lol

Thanks man ... you made my morning!
#4

[eluser]Nick Husher[/eluser]
Uh. Thanks. I guess. Smile
#5

[eluser]skattabrain[/eluser]
LOL Smile
#6

[eluser]jackbenning[/eluser]
Seriously! TY SOOOOOOOOOOOOOOO Much! Sending more than one XML-RPC response array FTW!
#7

[eluser]socs[/eluser]
Another thing to watch out for is blank values will also trigger the
"htmlspecialchars() expects parameter 1 to be string" error.

For example if
Code:
$state->name

above is "" then you will get this error. I had to put a bunch of checks in my code for this case.




Theme © iAndrew 2016 - Forum software by © MyBB