Forum Moderators: coopster

Message Too Old, No Replies

Passing query results through a function?

         

lorax

2:01 pm on Nov 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I've got a function for a SOAP server that makes a database query based on the parameters supplied and then iterates through the result set. The result set can be one or hundreds of rows.

My question is what is the best way to package (especially the multiple row results) and send these results back through the function to the SOAP client? Do I need to take apart the result array as I loop through the result set and stuff the contents into a new array:

for($i=1; $i<=$num_rows; $i++) {
$arr = mysql_fetch_array($results);
$pkg[] = array("res1" => $arr[0], "res2" => $arr[1]);
}

Or is there an easier way?

lorax

4:36 pm on Nov 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Well, it may not be pretty but I did the following.

For the server (where the function resides):

for($i=1; $i<=$num_rows; $i++) {
$arr = mysql_fetch_array($result);
$page[] = "$arr[0],$arr[1],$arr[2],$arr[3],$arr[4]";
}
return $page;

And on the client end I wrote:

$page = $soapclient->call('thefunction');
$num_rows = count($page);
for($i=0; $i<$num_rows; $i++) {
$arr = explode(",",$page[$i]);
echo "$arr[0] - $arr[1] - $arr[2] - $arr[3]<br />";
}

The formatting will be changed but I wanted something I could take apart and use.

On the server side I kept trying things like

$page[] = array($arr[0],$arr[1],...) thinking I'd be able to access it using a similar for loop and

$page[$i][0] - $page[$i][1] and so on - but it didn't work out. The var_dump gave me something that didn't make any sense so I opted for the brute force method.

daisho

2:19 pm on Nov 24, 2003 (gmt 0)

10+ Year Member



Hey Lorax,

Not sure if this would be easier but you could serialize the array on the server side then deserialize on the client side. This *should* let you pass a Multi-Dimensional array and not have it break.

lorax

4:28 pm on Nov 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Oy daisho - I should have thought of that! I'll give it a go, thanks.

jatar_k

4:44 pm on Nov 24, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



For some functions we use a token and just pass a chunk of data then split it up on the other side.

daisho

7:00 pm on Nov 24, 2003 (gmt 0)

10+ Year Member



I do that alot also. When I go that far to ensure everything will work I use urlencode/urldecode to create a "GET" string that's encoded the same.

daisho.