0

I have a probably very basic question, but I can't figure it out. (almost weekend ;P ) I have this function ReadOpenCalls(int relation) which gets the open calls from a relation.

List<string> messages = new List<string>();

if (inboundSet != null && inboundSet.RecordCount > 0)
{
    inboundSet.MoveFirst();

    do
    {
        messages.Add(inboundSet.Fields["DESCRIPTION"].Value.ToString());
        messages.Add(inboundSet.Fields["PK_R_INBOUNDMESSAGE"].Value.ToString());

        inboundSet.MoveNext();
    }
    while (!inboundSet.EOF);

    return messages;
}

It's called via WCF into a PHP page. Now that all works perfectly fine, my only problem is the output of it:

stdClass Object ( [string] => Array ( [0] => Webservice [1] => 1004 [2] => Webservice [3] => 1005 [4] => Webservice [5] => 1006 [6] => Webservice [7] => 1007 [8] => Webservice [9] => 1008 [10] => Webservice [11] => 1009 [12] => Webservice [13] => 1010 [14] => Webservice [15] => 1011 ) )

And I really want the output to have the "Webservice and ID's" in this case to be together and not all in one big array.

So something like

[0] => Webservice,
       1004
[1] => Webservice,
       1005

Please help me with some examples or a shot in the good direction. I will buy you a beer after ;)

2
  • This has nothing to do with PHP. Your C# code creates a flat list and naturally that's what you can access in PHP. What is your question here? Are you asking how to change the C# code? Commented Jun 6, 2013 at 6:56
  • Yes, I really want to know how I can achieve the output I want. I'm not very experienced with .NET so any shot in the good direction is good :D Commented Jun 6, 2013 at 7:00

1 Answer 1

3

Instead of calling the Addmethod twice, like you do here:

 do
 {
    messages.Add(inboundSet.Fields["DESCRIPTION"].Value.ToString());
    messages.Add(inboundSet.Fields["PK_R_INBOUNDMESSAGE"].Value.ToString());
    inboundSet.MoveNext();
 }

Just call it once per iteration, and add both values.

 do
 {
    string desc = inboundSet.Fields["DESCRIPTION"].Value.ToString();
    string inboundMsg = inboundSet.Fields["PK_R_INBOUNDMESSAGE"].Value.ToString()
    messages.Add(desc  +", "+inboundMsg );
    inboundSet.MoveNext();
 }

If the linebreak is required, then do this:

 do
 {
    string desc = inboundSet.Fields["DESCRIPTION"].Value.ToString();
    string inboundMsg = inboundSet.Fields["PK_R_INBOUNDMESSAGE"].Value.ToString()
    messages.Add(desc  +",\n"+inboundMsg );
    inboundSet.MoveNext();
 }
Sign up to request clarification or add additional context in comments.

3 Comments

I owe you a beer! Thank you very much, but can you please explain what you did now? You gave a name at the 2 values and then added them together? I think I get it now. :D
@Marijke you are welcome. I only added the names desc and inboundMsg to make the code "looks nice". You could just as easy do it in one line: messages.Add(inboundSet.Fields["DESCRIPTION"].Value.ToString()+", "+inboundSet.Fields["PK_R_INBOUNDMESSAGE"].Value.ToString()); without the variables :)
Just like I thought, nah it looks better with the names haha ;) You really saved my day AND weekend!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.