Hello everybody, I also have a problem with a script containing llhttprequest.
I want the script to send requests to a web server and ask for the contents of a table. The table contains 3 columns: Question, Answer, Tip. I want to send the requests 30 times and take as a return 3 lists, each one containing the questions, the answers and the help. My lsl script is the following:
key param1; // just to check if we're getting the result we've asked for; all scripts in the same object get the same replieskey param2;key param3;list question;list answer;list tip;default{ state_entry() { llSetText("Retrieve questions", <0.9, 0.4, 0.1>, 1.0); } touch_start(integer num) { integer i; for ( i = 1; i <= 30; i++ ) { param1 = llHTTPRequest("http://papavasa.webpages.auth.gr/opensim/send_data.php", [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"], "paramQ=" + i); param2 = llHTTPRequest("http://papavasa.webpages.auth.gr/opensim/send_data.php", [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"], "paramA=" + i); param3 = llHTTPRequest("http://papavasa.webpages.auth.gr/opensim/send_data.php", [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"], "paramT=" + i); } } http_response(key request_id, integer status, list metadata, string body) { if (request_id == param1) question += llParseString2List(body,["\n"],[" "]); llOwnerSay( (string)question ); if (request_id == param2) answer += llParseString2List(body,["\n"],[" "]); llOwnerSay( (string)answer ); if (request_id == param3) tip += llParseString2List(body,["\n"],[" "]); llOwnerSay( (string)tip ); //llOwnerSay(body); } }
And my php code is this:
<?// Only works with PHP compiled as an Apache module$headers = apache_request_headers();$objectName = $headers["X-SecondLife-Object-Name"];$objectKey = $headers["X-SecondLife-Object-Key"];$ownerKey = $headers["X-SecondLife-Owner-Key"];$ownerName = $headers["X-SecondLife-Owner-Name"];$region = $headers["X-SecondLife-Region"];// and so on for getting all the other variables ...// get things from $_POST[]// Naturally enough, if this is empty, you won't get anything$parameter1 = $_POST["paramQ"];$parameter2 = $_POST["paramA"];$parameter3 = $_POST["paramT"];// Connect to MySQL$con = mysql_connect("localhost","stesia","stesia");if (!$con) { die('Could not connect: ' . mysql_error()); }// Select the databasemysql_select_db("stesia") or die("Unable to select database: " . mysql_error());// Select only the row of the sent parametersif ( $parameter1 ){$result = mysql_query(" SELECT * FROM questions WHERE ID='" .$parameter1. "' ");$r = mysql_fetch_array($result);echo $r['Question'] . "\n";}else if ( $parameter2 ){$result = mysql_query(" SELECT * FROM questions WHERE ID='" .$parameter2. "' ");$r = mysql_fetch_array($result);echo $r['Answer'] . "\n";}else if ( $parameter3 ){$result = mysql_query(" SELECT * FROM questions WHERE ID='" .$parameter3. "' ");$r = mysql_fetch_array($result);echo $r['Help'] . "\n";}// close the connectionmysql_close($con);?>
My problem is that the data returned is not in order (as in the table). I want to save the data in 3 different lists, one for questions, one for answers and one for tips. I don't know if i use correctly the http_request and response and the lists part..
I would very much appreciate it if anyone could help me out. Thank you in advance! :matte-motes-bashful-cute: