Skip to main content
wfzen
Inspiring
April 2, 2016
Question

read string SQL data from ASP

  • April 2, 2016
  • 1 reply
  • 633 views

I had script like the one below to read data:

function getDataFromSQL(): void {

  var myTextLoader: URLLoader = new URLLoader();

  myTextLoader.dataFormat = URLLoaderDataFormat.VARIABLES;

  myTextLoader.addEventListener(Event.COMPLETE, onLoaded);

  function onLoaded(e: Event): void {

  var tAverage = (e.target.data.Average);

  var tTotalVotes = (e.target.data.TotalVotes);

  var tTotalRate1 = (e.target.data.star1);

  var tTotalRate2 = (e.target.data.star2);

  var tTotalRate3 = (e.target.data.star3);

  var tTotalRate4 = (e.target.data.star4);

  var tTotalRate5 = (e.target.data.star5);

  var temp = tTotalRate5 + "\n" + tTotalRate4 + "\n" + tTotalRate3 + "\n" + tTotalRate2 + "\n" + tTotalRate1;

  totalForEachStar.text = temp;

  tAve.text = tAverage;

  totalVotes.text = "(" + tTotalVotes + ")";

  }

  var extraString = Math.random();

  myTextLoader.load(new URLRequest("http://dntin1web01/tpas/SQL/GniePageRatePageReadLastEntryOnly.asp?fileName=" + tPage + "&qs=" + extraString));

}

Now I have a string like the one below. What modification do I need to make in order to read the string.

153^0^&154^0^&155^0^&156^0^&157^0^&158^0^&159^0^&173^1^2015-12-31&174^1^2015-12-31&175^1^2015-12-31&176^0^&177^1^2015-12-31&178^1^2015-12-31&179^1^2015-12-31

Thanks,

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
April 2, 2016

1.  don't nest named functions.

2. what do you mean by, 'now i have a string...'?

wfzen
wfzenAuthor
Inspiring
April 4, 2016

Thank you for the quick response, kglad.

I think the output data was like star1=3&star2=4.... and I can pick up the value by var tTotalRate1 = (e.target.data.star1); then 3 would be the value for tTotalRate1. Now it's a string like 153^0^&154^0^&155^0^&156^0^&..... What I would like to do is the capture the whole text and then use Actionscript to get the values separated by ^ and & symbols.

Can explain "nest named functions" a little bit? Do you mean not to use function onLoaded(e: Event): void { ... } inside?


Thanks,


cpliu

kglad
Community Expert
Community Expert
April 4, 2016

you should unnest:

function getDataFromSQL(): void {

  var myTextLoader: URLLoader = new URLLoader();

  myTextLoader.dataFormat = URLLoaderDataFormat.VARIABLES;

  myTextLoader.addEventListener(Event.COMPLETE, onLoaded);

  var extraString = Math.random();

  myTextLoader.load(new URLRequest("http://dntin1web01/tpas/SQL/GniePageRatePageReadLastEntryOnly.asp?fileName=" + tPage + "&qs=" + extraString));

}

function onLoaded(e: Event): void {

  var tAverage = (e.target.data.Average);

  var tTotalVotes = (e.target.data.TotalVotes);

  var tTotalRate1 = (e.target.data.star1);

  var tTotalRate2 = (e.target.data.star2);

  var tTotalRate3 = (e.target.data.star3);

  var tTotalRate4 = (e.target.data.star4);

  var tTotalRate5 = (e.target.data.star5);

  var temp = tTotalRate5 + "\n" + tTotalRate4 + "\n" + tTotalRate3 + "\n" + tTotalRate2 + "\n" + tTotalRate1;

  totalForEachStar.text = temp;

  tAve.text = tAverage;

  totalVotes.text = "(" + tTotalVotes + ")";

  }

and, as long as, those data make sense to you, you can use split:

var dataA:Array = e.target.data.split("&");

for(var i:int=0;i<dataA.length;i++){

dataA=dataA.split("^");

dataA.pop();

}

then dataA][0] is the left-most number between ampersands and dataA[1] is the right-most number between the same (kth) ampersand.  you might have an empty value that should be pop'ed if that string ends in an ampersand