One checkbox but needs to become two different names

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hodgenpodg
Forum Newbie
Posts: 1
Joined: Tue Dec 06, 2005 3:07 pm

One checkbox but needs to become two different names

Post by hodgenpodg »

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Code: Select all

<?php

if (!eregi("modules.php", $PHP_SELF)) {
   die ("No puedes acceder directamente al archivo...");

}

require_once("mainfile.php");

require('bf2s-mlb.php');
ob_start("ob_gzhandler");

include("header.php");

    $mlb->debug = false;

        $rankkeys = array(
         "0" => array("rank" => "Private",            "req" => 0),
         "1" => array("rank" => "Private First Class",        "req" => 150),
         "2" => array("rank" => "Lance Corporal",        "req" => 500),
         "3" => array("rank" => "Corporal",            "req" => 800),
         "4" => array("rank" => "Sergeant",            "req" => 2500),
         "5" => array("rank" => "Staff Sergeant",        "req" => 5000),
         "6" => array("rank" => "Gunnery Sergeant",        "req" => 8000),
         "7" => array("rank" => "Master Sergeant",        "req" => 20000),
         "8" => array("rank" => "First Sergeant",        "req" => 20000),
         "9" => array("rank" => "Master Gunnery Sergeant",    "req" => 50000),
        "10" => array("rank" => "Sergeant Major",        "req" => 50000),
        "11" => array("rank" => "Sergeant Major of the Corps",    "req" => 250000),
        "12" => array("rank" => "2nd Lieutenant",        "req" => 250000) //don't know yet
    );

    function sec2log($seconds) {
        $h = floor($seconds / 3600);
        $m = floor(($seconds % 3600) / 60);
        $s = floor(($seconds % 3600) % 60);
        $h=sprintf("%02d", $h);
        $m=sprintf("%02d", $m);
        $s=sprintf("%02d", $s);
        return "{$h}:{$m}:{$s}";
    }
    
    opentable ();
    echo "<center><FONT SIZE=\"2\" color=\"white\"><b>Titanium Soldiers Leaderboard</b></center>";
    closetable();
    opentable ();
    
?>

  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <script type="text/javascript" src="modules/leaderboard/mlb.js" ></script>
  <link rel="stylesheet" href="modules/leaderboard/mbl.css" type="text/css" />


<?php
    //no more than 64 pid's per request! Anything more than 64 get's ignored...
    //NO NAMES! PID's ONLY!
    //just a bunch(40) of PID's from various EA leader boards. Replace with your own.
    //these all get joined together into a new var, and sent as one string later..
    $PIDlist = array(
        "squad_a" => "43770197,43691364,46568714,44189433"
    );

    //turn the PID's into multi-dimensional arrays, for comparing against the XLM cache, and multiple group tables.
    $squadgroup = array();
    foreach( $PIDlist as $k => $v ) {
        $v = preg_replace('/\s/', '', $v); //strip all whitespaces (jic)
        $grouppid .= $v . ","; //add all pid's into one string for feed
        $squadgroup[$k] = explode(',', $v);
    }
    if( substr($grouppid,-1, 1) == ","); //better check it first
        $grouppid = substr($grouppid,0,strlen($grouppid)-1); //trim off the last comma

    $mlb->get($grouppid); //get raw xml data array
//echo "<pre>\n";
//echo print_r($squadgroup);
//echo "</pre>\n";
      
?>

<style type="text/css">
<!--
.style5 {font-size: 10px; font-weight: bold; }
.style6 {font-size: 14px}
-->
</style>
<br>

<form name="compare" method="get" action="http://bf2s.com/compare.php">



<p align="center">

<table border="0" cellpadding="0" cellspacing="0" width="53%">
  <tr>
    <td>

      <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
          <td align="left"><input type="submit" onClick="setItems_redir();" value="Compare" enabled>
          &nbsp;&nbsp;Select two players to compare stats!</td>
        </tr>
      </table>

<?php
    $leadercache = $mlb->getList('score'); //only need to call this once, default sort by 'score'
    foreach( $squadgroup as $group => $squad ) { //cycle through each group array
?>
      <table border="0" cellpadding="0" cellspacing="0" id="<?=$group?>" class="leader sortable" width="100%">
        <!--DWLayoutTable-->
        <tr>
          <th width="28" height="19" class="nosort" id="hdr" style="padding: 0px 6px; text-align: right;"><img src="images/compare.gif" alt="Compare Players" width="16" height="16" style="border: 0;"/></th>
          <th width="32" class="nosort" id="hdr">&nbsp;</th>
          <th valign="middle" id="hdr" style="padding-left: 4px; text-align: left;"><div align="left" class="style5">
            <h4 class="style6">Player</h4>
          </div></th>
          <th width="96" valign="middle" id="hdr" style="padding: 0px; text-align: right;"><div align="left" class="style5">
            <div align="left">
              <h4 class="style6">Score</h4>
            </div>
          </div></th>
          <th width="70" valign="middle" id="hdr" style="padding: 0px; text-align: right;"><div align="left" class="style5">
            <div align="left">
              <h4 class="style6">K/D</h4>
            </div>
          </div></th>
          <th width="79" valign="middle" id="hdr" style="padding: 0px; text-align: right;"><div align="left" class="style5">
            <div align="left">
              <h4 class="style6">W/L</h4>
            </div>
          </div></th>
          <th width="80" valign="middle" id="hdr" style="padding: 0px; text-align: right;"><div align="left" class="style5">
            <div align="left">
              <h4 class="style6">SPM</h4>
            </div>
          </div></th>
          <td width="100" valign="middle"><div align="left" class="style5">
            <h4 class="style6">Time</h4>
          </div></td>
          <td width="94" valign="middle"><div align="left" class="style5">
            <h4 class="style6">Progress</h4>
          </div></td>
        </tr>
<?php
        foreach( $leadercache as $players ) { //cycle through each sub-array
            if ( in_array($players['PID'], $squad) ) { //verify, else loop

                //No one knows for sure what happens past Sergeant Major of the Corps
                //I suspect they become 2nd Lieutenant after Sergeant Major of the Corps, and stay there. (until expansion?)
                if ( ($players['RANK'] >= 11) ) {
                        $pcntDiff = number_format( 100, 2);
                        $newrank = "At ease soldier!";
                } else {
                    //Master Sergeant cannot advance to First Sergeant
                    //Master Gunnery Sergeant cannot advance to Sergeant Major
                    if(($players['RANK'] == 7) || ($players['RANK'] == 9))
                        $nextrank = $players['RANK'] + 2;
                    else
                        $nextrank = $players['RANK'] + 1;

                    $requiredPoints = $rankkeys[$nextrank]['req'];    //Required Points for next rank
                    $pointDiff = ($requiredPoints - $players['SCORE']);    //Point differential for next rank

                    if($pointDiff <= 0) {//WTF? over...
                        $pcntDiff = number_format( 100, 2);
                        //gotta find their proper/next rank..
                        foreach( $rankkeys as $k => $v ) {
                            if($rankkeys[$k]['req'] >= $players['SCORE']) {
                                $newrank = $rankkeys[($k - 1)]['rank']; //This is where they're supposed to be
                                break;
                            }
                        }
                    } else {
                        $pcntDiff = number_format( (($players['SCORE'] / $requiredPoints) * 100), 2);
                        $newrank = $rankkeys[$nextrank]['rank'];
                        $approx = sec2log( floor(($players['TIME'] / $players['SCORE']) * $pointDiff) );
                        $newrank .= "<br />Aprox.: " . $approx;
                    }
                }
?>
        <tr>
          <td valign="middle" width="28" nowrap><input name="pid" type="checkbox" onclick="setItems(this);" value="<?=$players['PID']?>"></td>
          <td valign="middle" width="32" nowrap><img src="images/bf2/rank_small_<?=$players['RANK']?>.gif" alt="<?=$rankkeys[$players['RANK']]['rank']?>" style="border: 0;"/></td>
          <td valign="middle" width="140" style="padding-left: 4px; text-align: left;"><div align="left"><a href="<?=$players['LINK']?>" target="_blank">
                <?=$players['NICK']?>
          </a></div></td>
          <td><?=number_format($players['SCORE'], 0, ',', ',')?>
            <div align="left"></div></td>
		  <td><?=number_format($players['KDR'], 2)?>
		    <div align="left"></div></td>
		  <td><?=number_format($players['WLR'], 2)?>
		    <div align="left"></div></td>
          <td><?=number_format($players['SPM'], 2)?>
            <div align="left"></div></td>
          <td><?=sec2log($players['TIME'])?>
            <div align="left"></div></td>
          <td alt="Next Rank: <?=$newrank?>">
            <div class="progressbar">
              <div class="progress" style="width:<?=number_format($pcntDiff, 0) ?>%"><?= $pcntDiff ?>%</div>
            </div>
          </td>
        </tr>
<?php
            }
        }
?>
      </table>

<?php
    }
?>
      <table border="0" cellpadding="0" cellspacing="0" width="100%" class="misc">
        <tr>
          <td align="left" valign="top"><em>Stats from <a href="http://www.bf2s.com" TARGET="_BLANK">bf2s.com</a></em></td>
          <td align="right"><?php echo "Last Update: " . $mlb->cacheage; ?><br /><?php echo "Next Update: " . $mlb->nextrefresh; ?></td>
        </tr>
      </table>

    </td>
  </tr>
</table>
</p>
</form>

</body>



<?php if($mlb->debug) { ?>
<!-- View page source to see debug info
<pre>
  <?php $mlb->printLog(); ?>
</pre>
-->
<?php } 

closetable();
include("footer.php");
?>
ive modified this code to suit my needs but one thing that I cant get to work (and that was disabled when it was given to me) is the compare feature. There is a checkbox next to each player name (which i believe are in an array) and the checkbox corresponds to there personal id #. Now what im trying to do is make it so when two checkboxes are checked and you clikc compare it sends those to values to http://bf2s.com/compare.php?pid1=(1st checked box pid)&pid2=(2nd checked box pid) I made it work using two checkbox columns on my website http://www.titaniumsoldiers.frih.net/mo ... ld_2_Stats but I dont really like that way id rather have just one column of checkboxes. Also id rather not have to make a checkbox for each person because I'll be adding/dropping players often.

thanks in advance for your help


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Post Reply