NATION

PASSWORD

Coding help

Bug reports, general help, ideas for improvements, and questions about how things are meant to work.
User avatar
Letoilenoir
Chargé d'Affaires
 
Posts: 424
Founded: Nov 26, 2010
Ex-Nation

Coding help

Postby Letoilenoir » Thu Aug 23, 2012 10:49 am

Not too sure where to post this so apologies if it is the wrong area

Is there anybody who could point me in the direction of how to make this (or something like it) into a working reality?

What would I need (server side?) to make it output a result to the applicant? Not too bothered about recording the results of each completion for future use

Sorry if I am rather vague but I have very little notion of asp sql etc etc
KEEP THE BLOOD CAVE FREE

User avatar
BrownLands
Bureaucrat
 
Posts: 50
Founded: Jun 17, 2012
Ex-Nation

Postby BrownLands » Thu Aug 23, 2012 10:52 am

All I know is that NationStates was coded in Perl

User avatar
Goddess Technical Help Line
Civil Servant
 
Posts: 10
Founded: Aug 21, 2012
Ex-Nation

Postby Goddess Technical Help Line » Thu Aug 23, 2012 10:56 am

Server side? Nothing, if you don't want to store the result yourself. That page could be made on the client side with javascript. What you showed is a HTML form with some heavy CSS for the font and the background, and javascript to make the results.

If you are not familiar with them: http://w3schools.com
And Nuts&Bolts is for the technical help (bug report/feature request) of NationStates. I think this would belong to F7.

EDIT: If you insist on processing the result on server side, try PHP. IMO, it's easier to learn (especially after working with C) and code in than JS.
I might suggest assigning a score value to each of the answers (eg. strongly disagree being 0 and strongly agree being 3) and making the questions to follow this. After the form is submitted to the results page (either with POST or AJAX XML), you can process it by simply adding up the values, and a switch-case or if/elseif/else branch, like the lowest scores being victims, and the highest scores being raiders...

Coding of this would be very easy if you have the idea.
Last edited by Goddess Technical Help Line on Thu Aug 23, 2012 11:05 am, edited 1 time in total.

User avatar
Letoilenoir
Chargé d'Affaires
 
Posts: 424
Founded: Nov 26, 2010
Ex-Nation

Postby Letoilenoir » Thu Aug 23, 2012 11:55 am

Many many thanks & apologies if this should have gone elsewhere (not familiar wit the F7 section)

Yes the logic is that the questions will be weighted so that the cumulative scores will produce a range of results in the form of "You have a heavy bais towards XXXX you should consider joining a Roleplay region etc" and if php can do this server side then I have a indication of which path to tread

guess this is a good starting point?
Last edited by Letoilenoir on Thu Aug 23, 2012 12:03 pm, edited 1 time in total.
KEEP THE BLOOD CAVE FREE

User avatar
Goddess Technical Help Line
Civil Servant
 
Posts: 10
Founded: Aug 21, 2012
Ex-Nation

Postby Goddess Technical Help Line » Thu Aug 23, 2012 12:49 pm

Yep, this is what I though of. Remember to ask/look for php on your server (if it's not already provided, like in LAMPP/WAMP).

User avatar
Corporation de Apple
Diplomat
 
Posts: 609
Founded: Nov 05, 2010
Ex-Nation

Postby Corporation de Apple » Thu Aug 23, 2012 3:09 pm

Goddess Technical Help Line wrote:Yep, this is what I though of. Remember to ask/look for php on your server (if it's not already provided, like in LAMPP/WAMP).

If you have a third-party hosted solution, odds are you have PHP preinstalled.
If you need to get it, here's the official website: http://www.php.net/
Like Goddess Technical Help Line said, you can get LAMP/WAMP/Wampserver and it'll come with Perl, HTML, PHP and MySQL built-in.
The Hand of Thrawnn
Former things in Osiris
Frisbeeteria wrote:
Albul wrote:Everyone has said what they needed and now no one is saying anything relevant to the topic.

That describes pretty much every topic ever posted in NSG.
.

User avatar
[violet]
Executive Director
 
Posts: 16205
Founded: Antiquity

Postby [violet] » Thu Aug 23, 2012 11:02 pm

Do you just want a page that asks people a series of questions and tells them which category they fall into based on their answers? If so, there are lots of free online quiz/survey generators that will do that for you. This is one that jumped out at me, although I've never used it.

User avatar
Letoilenoir
Chargé d'Affaires
 
Posts: 424
Founded: Nov 26, 2010
Ex-Nation

Postby Letoilenoir » Thu Aug 23, 2012 11:49 pm

Most of the online services are designed on a correct/incorrect answer basis, so they are not geared to put the respondents into categories

I'm sure there is one out there somewhere, but if I found one that fitted the criteria then I wouldn't actually be learning anything, just customising a turnkey solution

I have managed to find a standalone php example that, with the help of the advice from above, I should be able to tweak to produce the desired effect

As an aside, most search results for php survey/quiz return solutions that promote the use of HTML,PHP and MySQL, so maybe I should consider dipping me toe into the database option!
Last edited by Letoilenoir on Thu Aug 23, 2012 11:51 pm, edited 1 time in total.
KEEP THE BLOOD CAVE FREE

User avatar
BrownLands
Bureaucrat
 
Posts: 50
Founded: Jun 17, 2012
Ex-Nation

Postby BrownLands » Fri Aug 24, 2012 2:46 am

Dont learn PHP! It is a awful language. Learn Perl instead. Perl is what NationStates was coded in. It is; Simpler, easier to learn and it can do more things.

User avatar
Goddess Technical Help Line
Civil Servant
 
Posts: 10
Founded: Aug 21, 2012
Ex-Nation

Postby Goddess Technical Help Line » Fri Aug 24, 2012 3:52 pm

IMO, learning a general purpose programming language for simple web-based form processing and databases is a bit overkill. Also PHP is more readily supported by cheap hosting providers, while with perl you might have to subscribe to a higher tier service or VPS.

User avatar
BrownLands
Bureaucrat
 
Posts: 50
Founded: Jun 17, 2012
Ex-Nation

Postby BrownLands » Sat Aug 25, 2012 2:59 am

Goddess Technical Help Line wrote:IMO, learning a general purpose programming language for simple web-based form processing and databases is a bit overkill. Also PHP is more readily supported by cheap hosting providers, while with perl you might have to subscribe to a higher tier service or VPS.

All very true, but he is not going (or at least I hope he is not) to code this and then forget about programming and give up. 99% of the big hosting company's support Perl and it is generally spreading to the smaller company's. It wont be to hard to find a cheap host who supports Perl nowadays.

User avatar
Letoilenoir
Chargé d'Affaires
 
Posts: 424
Founded: Nov 26, 2010
Ex-Nation

Postby Letoilenoir » Tue Sep 11, 2012 10:56 am

Looks like Uni has already got something along the lines I was aiming for up and running here

Nicely executed but not too sure about the colour scheme on the results page!

Seems from the source code to be a php job
Last edited by Letoilenoir on Tue Sep 11, 2012 11:35 am, edited 2 times in total.
KEEP THE BLOOD CAVE FREE

User avatar
Solm
Senator
 
Posts: 3582
Founded: Jul 23, 2008
Corporate Bordello

Postby Solm » Tue Sep 11, 2012 7:23 pm

Letoilenoir wrote:Seems from the source code to be a php job


Yeah, that was coded in PHP, data stored as json for the results. PHP is just so simple to process forms, and then generating an image was simple as well for this purpose. I did something similar for NS weather.
Last edited by Solm on Tue Sep 11, 2012 7:34 pm, edited 3 times in total.

Retired: ns .hellodot. solm @ gmail .dot. com

User avatar
Unibot II
Senator
 
Posts: 3852
Founded: Jan 10, 2011
Ex-Nation

Postby Unibot II » Tue Sep 11, 2012 7:49 pm

Letoilenoir wrote:-sic-


It's not publicly released yet, I'm still building a background of well-known figures to fill the celebrity chart. We're also working out technical kinks. But thanks!

By the way, I wasn't trying to copy you -- I hadn't seen this thread and had this idea for a long time. I just started working on it now because I had Solm to majorly help realize the idea now and I figured out what I wanted for the Y axis, which had been a mystery to me till I had a brain-wave one day when I thought of Francoism and then 10000 Islands and how I've almost become uncomfortable staying in one gameplay region and don't feel as, let's say, connected and then *HEAD-EXPLODES* exclusion v. inclusion, which I later refined as regionalism v. cosmopolitanism. Suddenly archetypes of game-players, The Lone Ranger, The Loose Cannon, The Patriot, The Lorax (WE MUST MAINTAIN OUR NEUTRALITY!), The Spartan, The Statesman, The Warmonger, The Drifter, The Region Whore etc. started to come to life in my head and Gameplay made a lot more sense to me. So I think its worth sharing with people.
Last edited by Unibot II on Tue Sep 11, 2012 7:59 pm, edited 1 time in total.
Vocenae wrote:Unibot, you have won NS.
General Halcones wrote:Look up to Unibot as an example.
Member of Gholgoth | The Capitalis de Societate of The United Defenders League (UDL) | Org. Join Date: 25/05/2008
Unibotian Factbook // An Analysis of NationStates Generations // The Gameplay Alignment Test // NS Weather // How do I join the UDL?
World Assembly Card Gallery // The Unibotian Life Expectancy Index // Proudly Authored 9 GA Res., 14 SC Res. // Commended by SC#78;
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
Duty is Eternal, Justice is Imminent: UDL

User avatar
Lordieth
Post Czar
 
Posts: 31603
Founded: Jun 18, 2010
New York Times Democracy

Postby Lordieth » Sun Sep 16, 2012 5:31 am

I'm not sure if you wanted a code sample, but anyway, this would be a starting point if you wanted to do it in PHP;

Code: Select all
<html>
<head>
<title>Choice</title>
</head>

<body>


<form action="choice.php" method="post">
<input type="radio" name="choice" value="agree" /> Agree
<input type="radio" name="choice" value="disagree" /> Disagree
<input type ="submit" value="Decide" />
</form>

</body>
</html>


<?php

$user = $_POST["choice"];
echo $user;

?>



I'm pretty sure that's right, but I couldn't get the script to print the variable on this computer. I hope it's because this computer I'm using just really sucks, because it won't even display phpinfo();.

If it is wrong, someone can correct me.

Edit; fixed it.
Last edited by Lordieth on Sun Sep 16, 2012 7:26 am, edited 1 time in total.
There was a signature here. It's gone now.

User avatar
Letoilenoir
Chargé d'Affaires
 
Posts: 424
Founded: Nov 26, 2010
Ex-Nation

Postby Letoilenoir » Sun Oct 28, 2012 1:49 pm

Keeping this all in one place here is another:

http://moruna.comoj.com/census1.php

Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Influence</title>
<style type="text/css" media="all">
      @import "http://www.nationstates.net/ns_v61.css";
   </style>
</head>

<body>

<input type="text" name="name[]" /><br />

<input type="text" name="name[]" /><br />

<input type="text" name="name[]" /><br />

<br />
<table><tr><th>Nation<th>Influence<th>Region
<?php
   function get_data($nation, $shards = FALSE) {
      if($shards != FALSE) {
         $file = 'http://www.nationstates.net/cgi-bin/api.cgi?nation=' . $nation . '&q=' . $shards;
      }
      else {
         $file = 'http://www.nationstates.net/cgi-bin/api.cgi?nation=' . $nation;
      }
     
      $xml = simplexml_load_file($file);
      return $xml;
   }
   ini_set('user_agent', 'Letoilenoir');
   function display_influence($nation) {
      $data = get_data($nation, 'name+influence+region');
     
      $name = (string) $data->NAME;
      $influence = (string) $data->INFLUENCE;
      $region = (string) $data->REGION;
   

     echo "<tr><td><a rel='nofollow' target='_blank' href='http://www.nationstates.net/nation=$name'>$name</a>";
     echo "<td>$influence</a>";
    echo "<td><a rel='nofollow' target='_blank' href='http://www.nationstates.net/region=$region'>$region</a>";
   
    }
   
   display_influence('General Halcones');
   display_influence('Unibot III');
   display_influence('Krulltopia');
   

   
   
?></table>
</body>
</html>


Basic synopsis is to be able to get the three input boxes at the top of the page to control the names of the nations that generate the API requests - I;m not even sure if this is possible on the one form/document but welcome any suggestions

PS the three nations have only been chosen for illustrative purposes
KEEP THE BLOOD CAVE FREE

User avatar
Letoilenoir
Chargé d'Affaires
 
Posts: 424
Founded: Nov 26, 2010
Ex-Nation

Postby Letoilenoir » Tue Jan 01, 2013 4:39 pm

With the help of a few resident code gurus this was created (code below)

The correct working model can now be found here
Code: Select all
<style type="text/css" media="all">
      @import "http://www.nationstates.net/ns_v61.css";
   </style>
</HEAD><BODY>
<table><tr><th>Region<th>Delegate<th>Endorsements<th>Population
<?php
// I removed the comments from this one. See other example for those :p
$dump = file_get_contents('regions.xml');
$array = explode('<REGION>',$dump);
array_shift($array);
foreach ($array as $value)
  {
  $delegatestart = strpos($value,'<DELEGATE>')+10;
  $delegateend = strpos($value,'</DELEGATE>');
  $delegatename = $regionname = substr($value,$delegatestart,$delegateend-$delegatestart);
      {
    $namestart = strpos($value,'<NAME>')+6;
    $nameend = strpos($value,'</NAME>');
    $regionname = substr($value,$namestart,$nameend-$namestart);
    $nationsstart = strpos($value,'<NUMNATIONS>')+12;
    $nationsend = strpos($value,'</NUMNATIONS>');
    $numnations = substr($value,$nationsstart,$nationsend-$nationsstart);
    $endosstart = strpos($value,'<DELEGATEVOTES>')+15;
    $endosend = strpos($value,'</DELEGATEVOTES>');
    $endos = substr($value,$endosstart,$endosend-$endosstart);
 
    echo "<tr><td><a rel='nofollow' target='_blank' href='http://www.nationstates.net/region=$regionname'>$regionname</a>";
    echo "<td><a rel='nofollow' target='_blank' href='http://www.nationstates.net/nation=$delegatename'>$delegatename</a>";
    echo "<td>$endos<td>$numnations";
    }
  }
?></table></BODY></HTML>



The regions.xml file contains several fields which can effectively be manipulated to "filter" the list, but the daily data file does not supply the region "tags" recently implemented

For example below is the API call that selects the regions with the "Isolationist" tag:

Code: Select all
http://www.nationstates.net/cgi-bin/api.cgi?q=regionsbytag;tags=isolationist


The question is this -Can the resultant XML file from this api call be coded into the above to "remove" this array of nations from the region.xmk file so that the code above does not show them in the output file?

Any help/suggestions welcome
Last edited by Letoilenoir on Mon May 18, 2015 12:24 pm, edited 2 times in total.
KEEP THE BLOOD CAVE FREE

User avatar
Scoochi2
Envoy
 
Posts: 207
Founded: Antiquity
Ex-Nation

Postby Scoochi2 » Tue Jan 01, 2013 4:58 pm

that code looks very familiar ;)

If I understand what you're after (a list of regions that doesn't include the ones from the call) then think of using array_diff()

Essentially, you have two arrays: a list of regions and a list of regions you *don't* want. Use array diff to work out which regions are NOT in the unwanted list.
I've had a busy day so won't do a working example, but the following should make you understand it.

Code: Select all
$allregions = array(); // array of regions in the game
$unwantedregions = array(); // array of regions from the isolationist call

$wantedregions = array_diff($allregions,$unwantedregions); // array of regions WITHOUT the isolationist tag.



OR you could just add something to the loop to check if the region currently being evaluated is in the array of unwanted regions.
Code: Select all
if (!in_array($currentregion,$unwantedregions))
// do stuff for this wanted region
Last edited by Scoochi2 on Tue Jan 01, 2013 4:59 pm, edited 1 time in total.
The problem with a UDP joke is that you have no idea if people got it.

User avatar
Letoilenoir
Chargé d'Affaires
 
Posts: 424
Founded: Nov 26, 2010
Ex-Nation

Postby Letoilenoir » Fri Mar 15, 2013 12:17 pm

Back with another(probably 101) coding question

The following php code delivers the required information on a finite number of nations - basically designed to augment the info available through a dossier

However, because it contains more than 50 calls to the API it is hitting the rate limit

I have tried to alleviate this by invoking the "sleep" function, but am not sure if I have coded it properly

It may also be that this is a rather Heath Robinson approach so any suggestions are welcome

Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css" media="all">
      @import "http://www.nationstates.net/ns_v61.css";
   </style><!--[if IE 5]>
<style type="text/css">
/* place css box model fixes for IE 5* in this conditional comment */
.twoColFixLt #sidebar1 { width: 230px; }
</style>
<![endif]--><!--[if IE]>
<style type="text/css">
/* place css fixes for all versions of IE in this conditional comment */
.twoColFixLt #sidebar1 { padding-top: 30px; }
.twoColFixLt #mainContent { zoom: 1; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
</style>
<![endif]--></head>

<body class="twoColFixLt">

<div id="container">
  <div id="sidebar1">
     <div id="mainContent">
    <h1> Ether </h1>
    <table><tr><th>Nation<th>Influence<th>WA<th>Endorsements<th>Region
<?php
   function get_data($nation, $shards = FALSE) {
      if($shards != FALSE) {
         $file = 'http://www.nationstates.net/cgi-bin/api.cgi?nation=' . $nation . '&q=' . $shards;
      }
      else {
         $file = 'http://www.nationstates.net/cgi-bin/api.cgi?nation=' . $nation;
      }
     
      $xml = simplexml_load_file($file);
      return $xml;
   }
   ini_set('user_agent', 'Letoilenoir');
   function display_strategic_report($nation) {
      $data = get_data($nation, 'name+influence+wa+endorsements+region');
     
      $name = (string) $data->NAME;
      $influence = (string) $data->INFLUENCE;
      $wa = (string) $data->UNSTATUS;
     $endorsements = (string) $data->ENDORSEMENTS;
     $region = (string) $data->REGION;
   
     echo "<tr><td><a rel='nofollow' target='_blank' href='http://www.nationstates.net/nation=$name'>$name</a>";
     echo "<td>$influence</a>";
    echo "<td>$wa</a>";
    echo "<td>$endorsements</a>";
    echo "<td><a rel='nofollow' target='_blank' href='http://www.nationstates.net/region=$region'>$region</a>";
       
    }
   
display_strategic_report('#1');
display_strategic_report('#2');
display_strategic_report('#3');
display_strategic_report('#4');
display_strategic_report('#5');
display_strategic_report('#6');
display_strategic_report('#7');
display_strategic_report('#8');
display_strategic_report('#9');
display_strategic_report('#10');
display_strategic_report('#11');
display_strategic_report('#12');
display_strategic_report('#13');
display_strategic_report('#14');
display_strategic_report('#15');
display_strategic_report('#16');
display_strategic_report('#17');
display_strategic_report('#18');
display_strategic_report('#19');
display_strategic_report('#20');
display_strategic_report('#21');
display_strategic_report('#22');
display_strategic_report('#23');
display_strategic_report('#24');
display_strategic_report('#25');
display_strategic_report('#26');
display_strategic_report('#27');
display_strategic_report('#28');
display_strategic_report('#29');
display_strategic_report('#30');
display_strategic_report('#31');
display_strategic_report('#32');
display_strategic_report('#33');
display_strategic_report('#34');
display_strategic_report('#35');
display_strategic_report('#36');
display_strategic_report('#37');
display_strategic_report('#38');
display_strategic_report('#39');
display_strategic_report('#40');
sleep(30);
display_strategic_report('#41');
display_strategic_report('#42');
display_strategic_report('#43');
display_strategic_report('#44');
display_strategic_report('#45');
display_strategic_report('#46');
display_strategic_report('#47');
display_strategic_report('#48');
display_strategic_report('#49');
display_strategic_report('#50');
display_strategic_report('#51');
display_strategic_report('#52');
display_strategic_report('#53');
display_strategic_report('#54');
display_strategic_report('#55');
display_strategic_report('#56');
display_strategic_report('#57');
display_strategic_report('#58');
display_strategic_report('#59');
display_strategic_report('#60');
display_strategic_report('#61');
display_strategic_report('#62');
display_strategic_report('#63');
display_strategic_report('#64');
display_strategic_report('#65');
display_strategic_report('#66');
display_strategic_report('#67');
display_strategic_report('#68');
display_strategic_report('#69');
display_strategic_report('#70');
display_strategic_report('#71');
display_strategic_report('#72');
display_strategic_report('#73');
display_strategic_report('#74');
display_strategic_report('#75');
display_strategic_report('#76');
display_strategic_report('#77');
display_strategic_report('#78');
display_strategic_report('#79');
display_strategic_report('#80');
sleep(30);
display_strategic_report('#81');
display_strategic_report('#82');
display_strategic_report('#83');
display_strategic_report('#84');
display_strategic_report('#85');
display_strategic_report('#86');
display_strategic_report('#87');
display_strategic_report('#88');
display_strategic_report('#89');
display_strategic_report('#90');
display_strategic_report('#91');
display_strategic_report('#92');
display_strategic_report('#93');
display_strategic_report('#94');
display_strategic_report('#95');
display_strategic_report('#96');
display_strategic_report('#97');
display_strategic_report('#98');
display_strategic_report('#99');
display_strategic_report('#100');
display_strategic_report('#101');
display_strategic_report('#102');
display_strategic_report('#103');
display_strategic_report('#104');





   
?></table>
<!-- end #container --></div>
</body>
</html>
KEEP THE BLOOD CAVE FREE

User avatar
Glen-Rhodes
Powerbroker
 
Posts: 9027
Founded: Jun 25, 2008
Ex-Nation

Postby Glen-Rhodes » Fri Mar 15, 2013 1:20 pm

That is definitely a... robust way to do it. I would go with a function like this, though:
Code: Select all
  function display_strategic_reports($arr) {
    for($i = 0; $i < count($arr); $i++) {
      if($count == 49) {
        $count = 0;
        sleep(30);
      }

      $nation = $arr[$i];

      $data = get_data($nation, 'name+influence+wa+endorsements+region');
   
      $name = (string) $data->NAME;
      $influence = (string) $data->INFLUENCE;
      $wa = (string) $data->UNSTATUS;
      $endorsements = (string) $data->ENDORSEMENTS;
      $region = (string) $data->REGION;

      $html = <<<HTML
        <tr>
          <td><a rel='nofollow' target='_blank' href='http://www.nationstates.net/nation=$name'>$name</a></td>
          <td>$influence</td>
          <td>$wa</td>
          <td>$endorsements</td>
          <td><a rel='nofollow' target='_blank' href='http://www.nationstates.net/region=$region'>$region</a></td>
        </tr>
HTML;
      echo $html;
      $count++;
    }
  }


Then just send an array of nation names to the display_strategic_reports() function. The function will count how many requests have been made, and pause the script for 30 seconds and then send the 50th request. However, this is probably a bad way to go about designing a tool like this. If you want to get the strategic reports of 500 nations, that's going to take you around 5 minutes. That's way too long of a script execution time. So just keep that in mind. Even processing 100 nations is going to require at least 30 seconds, which is the default upper execution time limit in PHP.

If you want to process that many nations, I would suggest paginating things, so that you're only processing 50 nations at a time and don't have to pause your script. You can divide the array of nations into sections, and request the section corresponding to the page number. (Ie, $arr1 for the first page, $arr2 for the second.) Or you can use AJAX to request 50 nations at a time. There are a lot of possibilities.

User avatar
Letoilenoir
Chargé d'Affaires
 
Posts: 424
Founded: Nov 26, 2010
Ex-Nation

Postby Letoilenoir » Fri Mar 15, 2013 2:10 pm

Many thanks for the swift response G-R the code that inspired this was one of you originals!

I'm guessing that this section in your above example is the part that calls the relevant array?

Code: Select all
$nation = $arr[$i];
KEEP THE BLOOD CAVE FREE

User avatar
Glen-Rhodes
Powerbroker
 
Posts: 9027
Founded: Jun 25, 2008
Ex-Nation

Postby Glen-Rhodes » Fri Mar 15, 2013 2:38 pm

Letoilenoir wrote:Many thanks for the swift response G-R the code that inspired this was one of you originals!

I'm guessing that this section in your above example is the part that calls the relevant array?

That's the part that gets the specific array element. I only did that so I didn't have to rewrite more of your code.

What you would want to do is build an array of nation names and then pass it as an argument to display_strategic_reports().

User avatar
Letoilenoir
Chargé d'Affaires
 
Posts: 424
Founded: Nov 26, 2010
Ex-Nation

Postby Letoilenoir » Thu Oct 24, 2013 1:31 pm

Scoochi2 wrote:that code looks very familiar ;)

If I understand what you're after (a list of regions that doesn't include the ones from the call) then think of using array_diff()

Essentially, you have two arrays: a list of regions and a list of regions you *don't* want. Use array diff to work out which regions are NOT in the unwanted list.
I've had a busy day so won't do a working example, but the following should make you understand it.

Code: Select all
$allregions = array(); // array of regions in the game
$unwantedregions = array(); // array of regions from the isolationist call

$wantedregions = array_diff($allregions,$unwantedregions); // array of regions WITHOUT the isolationist tag.



OR you could just add something to the loop to check if the region currently being evaluated is in the array of unwanted regions.
Code: Select all
if (!in_array($currentregion,$unwantedregions))
// do stuff for this wanted region


Code: Select all
<HTML><HEAD>
<style type="text/css" media="all">
      @import  "http://w11.zetaboards.com/c/22619/11/css.css";
   </style>
</HEAD><BODY>
<table><tr><th>Region<th>Delegate<th>Endorsements<th>Population<th>Power<th>Rank
<?php
$dump = file_get_contents('regions.xml');
$array = explode('<REGION>',$dump);
array_shift($array);

$allregions = array("Asgard","Ether","Astyria","Kingdom of Rohan","Osiris","Hyrule");
foreach ($allregions as $value)

// I get that the explode above opens up the REGIONS in the XML via an array but how, where do I then put a second array to loop through  to pull back dtails for only a select set eg("Asgard","Ether","Astyria","Kingdom of Rohan","Osiris","Hyrule") the resulting page brings back six results so its picking something up?

  {
  $delegatestart = strpos($value,'<DELEGATE>')+10;
  $delegateend = strpos($value,'</DELEGATE>');
  $delegatename = $regionname = substr($value,$delegatestart,$delegateend-$delegatestart);
      {
    $namestart = strpos($value,'<NAME>')+6;
    $nameend = strpos($value,'</NAME>');
    $regionname = substr($value,$namestart,$nameend-$namestart);
    $nationsstart = strpos($value,'<NUMNATIONS>')+12;
    $nationsend = strpos($value,'</NUMNATIONS>');
    $numnations = substr($value,$nationsstart,$nationsend-$nationsstart);
    $endosstart = strpos($value,'<DELEGATEVOTES>')+15;
    $endosend = strpos($value,'</DELEGATEVOTES>');
    $endos = substr($value,$endosstart,$endosend-$endosstart);
    $powerstart = strpos($value,'<POWER>')+7;
    $powerend = strpos($value,'</POWER>');
    $power = substr($value,$powerstart,$powerend-$powerstart);
    $iNumber = $iNumber  + 1;
 
    echo "<tr><td><a href='http://www.nationstates.net/region=$regionname'>$regionname</a>";
    echo "<td><a href='http://www.nationstates.net/nation=$delegatename'>$delegatename</a>";
    echo "<td>$endos<td>$numnations";
    echo "<td>$power";
    echo "<td>$iNumber";
    }
  }
?></table></BODY></HTML>



Result:http://moruna.comoj.com/delegate13.html

The code is only returning the desired number of results (6 regions) but its not pulling through the data - is the second array in the wrong place, or is it coded all wrong?
KEEP THE BLOOD CAVE FREE

User avatar
Letoilenoir
Chargé d'Affaires
 
Posts: 424
Founded: Nov 26, 2010
Ex-Nation

Postby Letoilenoir » Sat Dec 20, 2014 12:55 pm

http://moruna.comoj.com/syntax2.php
Image
Code: Select all
ini_set('user_agent', '**************'');
   function display_strategic_report($nation) {
      $data = get_data($nation, 'name+influence+wa+censusscore-65+censusscore-66');
     
      $name = (string) $data->NAME;
      $influence = (string) $data->INFLUENCE;
      $wa = (string) $data->UNSTATUS;
     $censusscore1 = (string) $data->CENSUSSCORE;
     $censusscore2 = (string) $data->CENSUSSCORE;
     $region = (string) $data->REGION;
   
     echo "<tr><td><a rel='nofollow' target='_blank' href='http://www.nationstates.net/nation=$name'>$name</a>";
     echo "<td>$influence</a>";
    echo "<td>$wa</a>";
    echo "<td>$censusscore1</a>";
    echo "<td>$censusscore2</a>";

http://moruna.comoj.com/syntax1.php
Image
Code: Select all
ini_set('user_agent', '*************');
   function display_strategic_report($nation) {
      $data = get_data($nation, 'name+influence+wa+censusscore-66+censusscore-65');
     
      $name = (string) $data->NAME;
      $influence = (string) $data->INFLUENCE;
      $wa = (string) $data->UNSTATUS;
     $censusscore1 = (string) $data->CENSUSSCORE;
     $censusscore2 = (string) $data->CENSUSSCORE;
     $region = (string) $data->REGION;
   
     echo "<tr><td><a rel='nofollow' target='_blank' href='http://www.nationstates.net/nation=$name'>$name</a>";
     echo "<td>$influence</a>";
    echo "<td>$wa</a>";
    echo "<td>$censusscore1</a>";
    echo "<td>$censusscore2</a>";



Okay this is probably 101 coding, but can anyone help on how to pull 2 Census scores through PHP?

I can get either -65 or -66 to pull though but not both at the same time

I've tried adjusting several parameters but I just can't seem to get both working together - ideas?
KEEP THE BLOOD CAVE FREE

User avatar
Belique
Chargé d'Affaires
 
Posts: 499
Founded: Sep 25, 2013
Ex-Nation

Postby Belique » Sat Dec 20, 2014 2:01 pm

When I add a shortcut, I use an anchor. However, in one of my dispatches, this doesn't work. The code is correct and I've checked it, and it only works on some of them. Here is the link:
http://www.nationstates.net/nation=beli ... /id=343671

The code is in there very top box you see, and the connections are scattered. Did I breaksome kind of limit or pattern? Someone please let me know asap. I need to have a few more pages by new years for my region. thanks
Pro: Christianity, History, Conservatism, Conservationism, Creationists, Tea Party Movement, Manufacturing, Tariffs, Life, Green Energy, Oil, Coal, and the South

Anti: Atheism, Islam, Buddism, Sikhism, Hinduism, Waste of Tax Dollars, Haddron Collider, Welfare, Abortion, Amnesty, and Liberal politics

Next

Advertisement

Remove ads

Return to Technical

Who is online

Users browsing this forum: Absolutus, Bagong Timog Mindanao, The Nafhaea

Advertisement

Remove ads