Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

http_response reads data records as one string....can I split?

Tomfox Wiranata
Registered User
Join date: 20 Dec 2006
Posts: 80
03-09-2007 05:02
Hi!

So far I can read several ID's from my external webserver into an lsl script. The problem is, that all id's get read as one string. But I need to read each ID individual to implement them in llGiveMoney.

PHP-Script
CODE


function cmd_get($params){
$req = array('slid');
foreach($req as $rkey){
$$rkey = mysql_real_escape_string($params[$rkey]);
}

$sql = "SELECT `id` FROM `mytable` ORDER BY `id` ASC LIMIT 0 , 10000";
$result = mysql_query($sql) or die(mysql_error());

while($row = mysql_fetch_row($result)){
for($i=0; $i<sizeof($row); $i++)
echo $row[$i];

}
}



SL-Script
CODE

default
{
touch_start(integer toucher)
{
urlStore = "http://myPage.com/Script.php?command=get&slid=id";
saveData = llHTTPRequest(urlStore,[HTTP_METHOD,"GET"],"");
}

http_response(key id,integer status, list meta, string body)
{
if(saveData==id)
{
llOwnerSay(body);
}
}

}


So I just do the output to see how the Data arrives in SL. If I read 10 ID's, they arrive as one big string. Do you know how I can split it up?

thx
Squirrel Wood
Nuteater. Beware!
Join date: 14 Jun 2006
Posts: 471
03-09-2007 05:12
MyList = llParseString2List(TheString,[","," ","|"],[""]);

This will parse any string to a list.

It will consider commas, spaces and pipes as delimiters for list elements and split the string where these occur.

You can then use llGetListLength to determine the number of elements in the list and then use a simple loop to..
llGiveMoney((key)llList2String(MyList,elementID),amountofmoney);
Tomfox Wiranata
Registered User
Join date: 20 Dec 2006
Posts: 80
03-09-2007 05:23
Squirrel, you are my hero :) THX