CodeIgniter Forums
trying to create an array for XML-RPC = FAIL - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: trying to create an array for XML-RPC = FAIL (/thread-13711.html)



trying to create an array for XML-RPC = FAIL - El Forum - 12-02-2008

[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);    
    }



trying to create an array for XML-RPC = FAIL - El Forum - 12-02-2008

[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);



trying to create an array for XML-RPC = FAIL - El Forum - 12-03-2008

[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!


trying to create an array for XML-RPC = FAIL - El Forum - 12-03-2008

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


trying to create an array for XML-RPC = FAIL - El Forum - 12-03-2008

[eluser]skattabrain[/eluser]
LOL Smile


trying to create an array for XML-RPC = FAIL - El Forum - 02-13-2009

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


trying to create an array for XML-RPC = FAIL - El Forum - 02-24-2009

[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.