Difference between revisions of "PHP Example for Subscriber List"

From Second Life Wiki
Jump to navigation Jump to search
m (Replaced <php> with <syntaxhighlight lang="php">)
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Something like..
This is something I did to help someone get the PHP code together for a subscriber list. The corresponding LSL script 'pulls' each line of the subscriber list using [[llHTTPRequest]] against this PHP script in a loop. The PHP should look something like:
<pre>
<syntaxhighlight lang="php">
<?php
<?php
//db connect variables
//db connect variables
$host = "mysql server address";
$host = "mysql server address";
Line 26: Line 27:
       mysql_query("INSERT INTO tbl_News VALUES ('$uuid')");
       mysql_query("INSERT INTO tbl_News VALUES ('$uuid')");
     }
     }
    //return to script
    echo $cm." complete.";
     break;
     break;
   case "rem":
   case "rem":
     mysql_query("DELETE FROM tbl_News WHERE uuid='$uuid'");
     mysql_query("DELETE FROM tbl_News WHERE uuid='$uuid'");
    //return to script
    echo $cm." complete.";
     break;
     break;
  }


//return to script
  case "tot":
echo $cm." complete.";
    if($uuid = "") { //place your key between the quotes here
      $q = mysql_query("SELECT * FrOM tbl_News");
      $tot = mysql_num_rows($q);  //get the total entries in the table
    }
      //return to script
      echo $cm."|".$tot;
      break;
 
    case "dist":
      $count = $_REQUEST['count'];
      $q = mysql_query("SEL3CT * FROM tbl_News");
      mysql_data_seek($q,$count);
      $row = mysql_fetch_row($q);
      echo $row[0];
      break;
}
 
mysql_close($con);
 
?>
?>
</pre>
</syntaxhighlight>
This isn't tested or anything but it should be pretty close, to give an idea what your list-building functions would look like.
 
This isn't tested or anything but it should be pretty close, to give an idea what you're
function script will be. [[User:ELQ Homewood|ELQ Homewood]] 04:33, 2 November 2009 (UTC)
 
Okay, untested again lol, but should work, or at least be pretty close. When sending command "dist" or whatever you make that distribution command, you need to send a variable "count" from your LSL script so the php knows where you are in the list. [[User:ELQ Homewood|ELQ Homewood]] 13:42, 2 November 2009 (UTC)
 
Tested from inworld now, enjoy![[User:ELQ Homewood|ELQ Homewood]] 15:01, 2 November 2009 (UTC)

Latest revision as of 12:38, 30 November 2023

This is something I did to help someone get the PHP code together for a subscriber list. The corresponding LSL script 'pulls' each line of the subscriber list using llHTTPRequest against this PHP script in a loop. The PHP should look something like:

<?php

//db connect variables
$host = "mysql server address";
$user = "mysql username";
$pw = "mysql password";
$db = "mysql database name";

//connect to db
$con = mysql_connect($host,$user,$pw);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db($db, $con);

//get variables from script
$uuid = $_REQUEST['UUID'];
$cm = $_REQUEST['command'];

//process variables
switch($cm) {
  case "add":
    if(!mysql_query("SELECT * FROM tbl_News WHERE uuid = '$uuid'")) {
      mysql_query("INSERT INTO tbl_News VALUES ('$uuid')");
    }

    //return to script
    echo $cm." complete.";
    break;

  case "rem":
    mysql_query("DELETE FROM tbl_News WHERE uuid='$uuid'");

    //return to script
    echo $cm." complete.";
    break;

  case "tot":
    if($uuid = "") { //place your key between the quotes here
      $q = mysql_query("SELECT * FrOM tbl_News");
      $tot = mysql_num_rows($q);  //get the total entries in the table
    }
      //return to script
      echo $cm."|".$tot;
      break;

    case "dist":
      $count = $_REQUEST['count'];
      $q = mysql_query("SEL3CT * FROM tbl_News");
      mysql_data_seek($q,$count);
      $row = mysql_fetch_row($q);
      echo $row[0];
      break;
}

mysql_close($con);

?>

This isn't tested or anything but it should be pretty close, to give an idea what you're function script will be. ELQ Homewood 04:33, 2 November 2009 (UTC)

Okay, untested again lol, but should work, or at least be pretty close. When sending command "dist" or whatever you make that distribution command, you need to send a variable "count" from your LSL script so the php knows where you are in the list. ELQ Homewood 13:42, 2 November 2009 (UTC)

Tested from inworld now, enjoy!ELQ Homewood 15:01, 2 November 2009 (UTC)