-3

Ok i edit my question i think i understand more now how to build a question.
The website: bit DOT ly/1MHItEH

I want to run a php code when span 3 is between 5 & 9.
The code which outputs this is $players and in the bottom there is a html output code

<td><span style='text-shadow: 0 0 10px #ffca00; color: #ffca00; font-size: 20pt;'>". $players ."</span></td>


This php code outputs a html table with different values for every added server.

For example if i add a new server to servers.php it will create a new span for that server with new values. So basicly it reads and outputs different values for every server.
So how can i just run extra php code if the span 3 is between 5 & 9?

<html>
<head>
<meta charset="utf-8">
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<style>
   tr td, tr th { text-align: center !important; }
   tr td.motd, tr th.motd { text-align: left !important; }
</style>

</head>

<body style="width: 100%; margin: 0 auto; height: 20px; ">

<table class='table table-bordered table-striped'> 

</br>   
   
   <?php
   error_reporting(0);
   
   function openserveriai() {

   }

   function closeserveriai() {

   }

   function getnextstring(&$data) {
    $temp="";
    $counter=0;
    while (ord($data[$counter++])!=0) $temp.=$data[$counter-1];
    $data=substr($data,strlen($temp)+1);
    return $temp;
   }
    
   function getnextbytevalue(&$data) {
    $temp=ord($data[0]);
    $data=substr($data,1);
    return $temp;
   }

   function addServer($ip) {
    
    $map = '';
    $players = '';
    $maxplayers = '';
    $servername = '';
    $output = '';
    $live_server = '0';
    $packet = '0';
    $packet = "\xFF\xFF\xFF\xFFTSource Engine Query\x00";
    $live_server = fsockopen("udp://".$ip);
     
    if(!$live_server)
    {
     $output = "Off";
    }
    else
    {
     fwrite($live_server, $packet);
     socket_set_timeout($live_server,1,0);
     $junk = fread($live_server,5);
     $status = socket_get_status($live_server);
     $do = 1;
     $server_info= "";
      
     while($do)
     {
      $str_1 = fread($live_server,1);
      $server_info .= $str_1;
      $status = socket_get_status($live_server);
      if($status["unread_bytes"] == 0) {$do = 0;}
     }
     fclose($live_server);
      
     if (strlen($server_info) > 0)
     {
      $success = 1;
      $junk = getnextstring($server_info);
      $servername = getnextstring($server_info);
      $map = getnextstring($server_info);
      $junk = getnextstring($server_info);
      $junk = getnextstring($server_info);
      $players = getnextbytevalue($server_info);
     }
      
     if ($players != '') {
      $players = $players;
     } else {
      $players = "0";
     }
      
     if ($maxplayers != '')
     {
      $maxplayers = $maxplayers;
     }
     else
     {
      $maxplayers = "0";
     }

     if ($output != "Full" and $players != "0" or $maxplayers != "0")
     {
      $output = $output;
     }
     else
     {
      $output = "<font color='#FF0000'>Offline</font>";
     }

     if ($map != '')
     {
      $map = $map;
     }
     else
     {
      $map = "--";
      $maxplayers = "--";
      $players = "--";
     }

     if ($servername != '') {
      $servername = $servername;
     }
     else
     {
      $servername = "--";
     }
    }
    if($players == $maxplayers && $players != '--')
    {
     $players = "" . $players . "";
    }
    else if($players > $maxplayers-3 && $players != '--')
    {
     $players = "" . $players . "";
    }
    else
    {
     $players = "" . $players . "";
    }
    if ( strlen($map) > 19 )
    {
     $map = substr($map, 0, 19) . '...';
    }
    
    echo "
     <tbody>
      <tr style='background: #10130d;'>
    ";
    if ($map == '--')
    {
     echo "<td><span style='background-color: #b85c5c; border-radius: .25em; padding: .2em .6em .3em; font-weight: bold; color: #fff; font-size: 10pt;'>Offline</i></span></td>";
    }
    else
    {
     echo "<td><span style='background-color: #5cb85c; border-radius: .25em; padding: .2em .6em .3em; font-weight: bold; color: #fff; font-size: 10pt; '>Online</i></span></td>";
    }
    echo "      
    
    <td><span style='color: #fff; font-size: 10pt;'>". $ip ."</span></td>
    <td><span style='text-shadow: 0 0 10px #ffca00; color: #ffca00; font-size: 20pt;'>". $players ."</span></td>
    </tr>
    </tbody>
    ";
   }

   openserveriai();

   include ('servers.php');

   closeserveriai();
   
   ?>
  </table>
 </body>
</html>
  • 1
    Please check out [What is the difference between client-side and server-side programming?](https://stackoverflow.com/q/13840429/6634591) – Luca Kiebel May 01 '18 at 12:39
  • So basically you want value of the third span ?? – Aman jaura May 01 '18 at 12:39
  • You can't simply 'run' a PHP (server-side) script via the client-side. You would need to post some data somewhere via http request. in order to 'trigger' the script. – Felipe Warrener-Iglesias May 01 '18 at 12:41
  • I know the difference between javascript and php.
    Simple sed, if third span is between 5 & 9 then run php file or php include.
    – Anders Andersson May 01 '18 at 12:41
  • @AndersAndersson you don't know the difference between JavaScript and PHP as you're using JavaScript to check a condition and expecting to use PHP once that condition is met. Not possible. JavaScript runs in a parsed document, in a parsed document PHP can't run because that is interpreted on the server. You will need to post to a URL to activate a script if that is the case. – Felipe Warrener-Iglesias May 01 '18 at 12:42
  • Well can php do the same thing then? If .innerHTML of third span between 5 & 9 then execute php code? – Anders Andersson May 01 '18 at 12:44
  • 1
    No but it can check the value it places in that html if the table is created with php and add something to it on the server – charlietfl May 01 '18 at 12:46
  • where does the '5' come from? – Jeff May 01 '18 at 12:47
  • 1
    This really sounds like an [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). What does this php code do and what exactly are you trying to accomplish? – charlietfl May 01 '18 at 12:48
  • From $total and its in a php file. The php file prints out 5. – Anders Andersson May 01 '18 at 12:49
  • then do a test for `$total` in that php file, right there. And call a function or include a script when it matches your criteria (between 5 and 9). No need to mess around with the later rendered html. – Jeff May 01 '18 at 12:51
  • As I understood it: you want to traverse generated html and make additional ajax calls to php backed as long number in a third column is between 5 and 9? Am I correct? – Chris Cynarski May 01 '18 at 12:53
  • @Chris Cynarski yes. But i dont need to be on the site for that script to work. I edited my first question. – Anders Andersson May 01 '18 at 12:55
  • I remade my question from scratch can you take a look again? – Anders Andersson May 01 '18 at 13:27

1 Answers1

0

You can do something like this

 <?php
        $total = 5;
        if ($total >= 5 && $total <= 9) {
             //Between 5 and 9
        } else {
            // Not between 5 and 9
        }
  ?>

<table class='table table-bordered table-striped'>  
    <tbody>
    <tr>
    <td><span>First</span></td>      
    <td><span>Second</span></td>
    <td><span><?php echo $total; ?></span></td>
    </tr>
    </tbody>
</table>

Then you can call that php page with

require('yourpage.php');
Sarpyjr
  • 177
  • 4