Daily Lucky Numbers:
1
4
8
25
36
43

Pickems help

Started by Fog, December 07, 2013, 09:32:32 PM

Previous topic - Next topic

Fog

Here's the code for the attachment below:

<?php
require('includes/application_top.php');

$weekStats = array();
$playerTotals = array();
$possibleScoreTotal 0;
calculateStats();

include(
'includes/header.php');
?>

<h1>Standings</h1>
<h2>Weekly Stats</h2>
<table cellpadding="4" cellspacing="0" class="table1">
<tr><th align="left">Week</th><th align="left">Winner(s)</th><th>Score</th></tr>
<?php
if (isset($weekStats)) {
$i 0;
foreach($weekStats as $week => $stats) {
$winners '';
foreach($stats[winners] as $winner => $winnerID) {
$tmpUser $login->get_user_by_id($winnerID);
switch ($user_names_display) {
case 1:
$winners .= ((strlen($winners) > 0) ? ', ' '') . trim($tmpUser->firstname ' ' $tmpUser->lastname);
break;
case 2:
$winners .= ((strlen($winners) > 0) ? ', ' '') . $tmpUser->userName;
break;
default: //3
$winners .= ((strlen($winners) > 0) ? ', ' '') . '<abbrev title="' trim($tmpUser->firstname ' ' $tmpUser->lastname) . '">' $tmpUser->userName '</abbrev>';
break;
}
}
$rowclass = (($i == 0) ? ' class="altrow"' '');
echo ' <tr' $rowclass '><td>' $week '</td><td>' $winners '</td><td align="center">' $stats[highestScore] . '/' $stats[possibleScore] . '</td></tr>';
$i++;
}
} else {
echo ' <tr><td colspan="3">No weeks have been completed yet.</td></tr>' "\n";
}
?>

</table>
<p>&nbsp;</p>

<h2>User Stats</h2>
<table cellpadding="0" cellspacing="0">
<tr valign="top">
<td>
<b>By Name</b><br />
<table cellpadding="4" cellspacing="0" class="table1">
<tr><th align="left">Player</th><th align="left">Wins</th><th>Pick Ratio</th></tr>
<?php
if (isset($playerTotals)) {
//arsort($playerTotals);
$i 0;
foreach($playerTotals as $playerID => $stats) {
$rowclass = (($i == 0) ? ' class="altrow"' '');
$pickRatio $stats[score] . '/' $possibleScoreTotal;
$pickPercentage number_format((($stats[score] / $possibleScoreTotal) * 100), 2) . '%';
switch ($user_names_display) {
case 1:
echo ' <tr' $rowclass '><td class="tiny">' $stats[name] . '</td><td class="tiny" align="center">' $stats[wins] . '</td><td class="tiny" align="center">' $pickRatio ' (' $pickPercentage ')</td></tr>';
break;
case 2:
echo ' <tr' $rowclass '><td class="tiny">' $stats[userName] . '</td><td class="tiny" align="center">' $stats[wins] . '</td><td class="tiny" align="center">' $pickRatio ' (' $pickPercentage ')</td></tr>';
break;
default: //3
echo ' <tr' $rowclass '><td class="tiny"><abbrev title="' $stats[name] . '">' $stats[userName] . '<abbrev></td><td class="tiny" align="center">' $stats[wins] . '</td><td class="tiny" align="center">' $pickRatio ' (' $pickPercentage ')</td></tr>';
break;
}
$i++;
}
} else {
echo ' <tr><td colspan="3">No weeks have been completed yet.</td></tr>' "\n";
}
?>

</table>
</td>
<td>&nbsp;</td>
<td>
<b>By Wins</b><br />
<table cellpadding="4" cellspacing="0" class="table1">
<tr><th align="left">Player</th><th align="left">Wins</th><th>Pick Ratio</th></tr>
<?php
if (isset($playerTotals)) {
arsort($playerTotals);
$i 0;
foreach($playerTotals as $playerID => $stats) {
$rowclass = (($i == 0) ? ' class="altrow"' '');
$pickRatio $stats[score] . '/' $possibleScoreTotal;
$pickPercentage number_format((($stats[score] / $possibleScoreTotal) * 100), 2) . '%';
switch ($user_names_display) {
case 1:
echo ' <tr' $rowclass '><td class="tiny">' $stats[name] . '</td><td class="tiny" align="center">' $stats[wins] . '</td><td class="tiny" align="center">' $pickRatio ' (' $pickPercentage ')</td></tr>';
break;
case 2:
echo ' <tr' $rowclass '><td class="tiny">' $stats[userName] . '</td><td class="tiny" align="center">' $stats[wins] . '</td><td class="tiny" align="center">' $pickRatio ' (' $pickPercentage ')</td></tr>';
break;
default: //3
echo ' <tr' $rowclass '><td class="tiny"><abbrev title="' $stats[name] . '">' $stats[userName] . '</abbrev></td><td class="tiny" align="center">' $stats[wins] . '</td><td class="tiny" align="center">' $pickRatio ' (' $pickPercentage ')</td></tr>';
break;
}
$i++;
}
} else {
echo ' <tr><td colspan="3">No weeks have been completed yet.</td></tr>' "\n";
}
?>

</table>
</td>
<td>&nbsp;</td>
<td>
<b>By Pick Ratio</b><br />
<table cellpadding="4" cellspacing="0" class="table1">
<tr><th align="left">Player</th><th align="left">Wins</th><th>Pick Ratio</th></tr>
<?php
if (isset($playerTotals)) {
$playerTotals sort2d($playerTotals'score''desc');
$i 0;
foreach($playerTotals as $playerID => $stats) {
$rowclass = (($i == 0) ? ' class="altrow"' '');
$pickRatio $stats[score] . '/' $possibleScoreTotal;
$pickPercentage number_format((($stats[score] / $possibleScoreTotal) * 100), 2) . '%';
switch ($user_names_display) {
case 1:
echo ' <tr' $rowclass '><td class="tiny">' $stats[name] . '</td><td class="tiny" align="center">' $stats[wins] . '</td><td class="tiny" align="center">' $pickRatio ' (' $pickPercentage ')</td></tr>';
break;
case 2:
echo ' <tr' $rowclass '><td class="tiny">' $stats[userName] . '</td><td class="tiny" align="center">' $stats[wins] . '</td><td class="tiny" align="center">' $pickRatio ' (' $pickPercentage ')</td></tr>';
break;
default: //3
echo ' <tr' $rowclass '><td class="tiny"><abbrev title="' $stats[name] . '">' $stats[userName] . '</abbrev></td><td class="tiny" align="center">' $stats[wins] . '</td><td class="tiny" align="center">' $pickRatio ' (' $pickPercentage ')</td></tr>';
break;
}
$i++;
}
} else {
echo ' <tr><td colspan="3">No weeks have been completed yet.</td></tr>' "\n";
}
?>

</table>
</td>
</tr>
</table>
<p>&nbsp;</p>
<?php
include('includes/footer.php');
?>


What I'd like to display is instead of:

12 DLPackers 7/14  it would look like this 12 DLPackers 7-7

or

13 Fog 13/16  it would look like this 13 Fog 13-3

The 12 and 13 are the weeks and the 7/14 or 13/16 are wins compared to the number of games that week.

the 7-7 or 13-3 would be a win-lose record for that week.  Then what I'd like to try and create is an overall leader board with wins and loses.

Instead of this:

By Pick Ratio
Player Wins Pick Ratio
Fog 1 19/31 (61.29%)
SoCalSaint 0 15/31 (48.39%)
DLPackers 1 14/31 (45.16%)
SloopyDave 0 5/31 (16.13%)
Jeep99tj 0 4/31 (12.90%)

By Overall Record
Player Wins-Loses
Fog 19-12 
SoCalSaint 15-16
DLPackers 14-17
SloopyDave 5-26
Jeep99tj  4-27

---------------------------
Is there a way to add that PHP code in a PHP Block or PHP page with simple portal?

Chen Zhen

#1

global $boarddir;
require_once($boarddir . '/includes/application_top.php');

$weekStats = array();
$playerTotals = array();
$possibleScoreTotal = 0;
calculateStats();

require_once($boarddir . '/includes/header.php');

echo '
<h1>Standings</h1>
<h2>Weekly Stats</h2>
<table cellpadding="4" cellspacing="0" class="table1">
<tr><th align="left">Week</th><th align="left">Winner(s)</th><th>Score</th></tr>';

if (!empty($weekStats)) {
$i = 0;
foreach($weekStats as $week => $stats) {
$winners = false;
foreach($stats['winners'] as $winner => $winnerID) {
$tmpUser = $login->get_user_by_id($winnerID);
switch ($user_names_display) {
case 1:
$winners .= ((strlen($winners) > 0) ? ', ' : '') . trim($tmpUser->firstname . ' ' . $tmpUser->lastname);
break;
case 2:
$winners .= ((strlen($winners) > 0) ? ', ' : '') . $tmpUser->userName;
break;
default: //3
$winners .= ((strlen($winners) > 0) ? ', ' : '') . '<abbrev title="' . trim($tmpUser->firstname . ' ' . $tmpUser->lastname) . '">' . $tmpUser->userName . '</abbrev>';
break;
}
}
$rowclass = (($i % 2 == 0) ? ' class="altrow"' : '');
echo ' <tr' . $rowclass . '><td>' . $week . '</td><td>' . $winners . '</td><td align="center">' . $stats['highestScore'] . '/' . $stats['possibleScore'] . '</td></tr>';
$i++;
}
} else {
echo ' <tr><td colspan="3">No weeks have been completed yet.</td></tr><br />';
}

echo '
</table>
<p>&nbsp;</p>

<h2>User Stats</h2>
<table cellpadding="0" cellspacing="0">
<tr valign="top">
<td>
<b>By Name</b><br />
<table cellpadding="4" cellspacing="0" class="table1">
<tr><th align="left">Player</th><th align="left">Wins</th><th>Pick Ratio</th></tr>';

if (!empty($playerTotals)) {
//arsort($playerTotals);
$i = 0;
foreach($playerTotals as $playerID => $stats) {
$rowclass = (($i % 2 == 0) ? ' class="altrow"' : '');
$pickRatio = $stats['score'] . '/' . $possibleScoreTotal;
$pickPercentage = number_format((($stats['score'] / $possibleScoreTotal) * 100), 2) . '%';
switch ($user_names_display) {
case 1:
echo ' <tr' . $rowclass . '><td class="tiny">' . $stats['name'] . '</td><td class="tiny" align="center">' . $stats['wins'] . '</td><td class="tiny" align="center">' . $pickRatio . ' (' . $pickPercentage . ')</td></tr>';
break;
case 2:
echo ' <tr' . $rowclass . '><td class="tiny">' . $stats['userName'] . '</td><td class="tiny" align="center">' . $stats['wins'] . '</td><td class="tiny" align="center">' . $pickRatio . ' (' . $pickPercentage . ')</td></tr>';
break;
default: //3
echo ' <tr' . $rowclass . '><td class="tiny"><abbrev title="' . $stats['name'] . '">' . $stats['userName'] . '<abbrev></td><td class="tiny" align="center">' . $stats['wins'] . '</td><td class="tiny" align="center">' . $pickRatio . ' (' . $pickPercentage . ')</td></tr>';
break;
}
$i++;
}
} else {
echo ' <tr><td colspan="3">No weeks have been completed yet.</td></tr><br />';
}
echo '
</table>
</td>
<td>&nbsp;</td>
<td>
<b>By Wins</b><br />
<table cellpadding="4" cellspacing="0" class="table1">
<tr><th align="left">Player</th><th align="left">Wins</th><th>Pick Ratio</th></tr>';

if (isset($playerTotals)) {
arsort($playerTotals);
$i = 0;
foreach($playerTotals as $playerID => $stats) {
$rowclass = (($i % 2 == 0) ? ' class="altrow"' : '');
$pickRatio = $stats['score'] . '/' . $possibleScoreTotal;
$pickPercentage = number_format((($stats['score'] / $possibleScoreTotal) * 100), 2) . '%';
switch ($user_names_display) {
case 1:
echo ' <tr' . $rowclass . '><td class="tiny">' . $stats['name'] . '</td><td class="tiny" align="center">' . $stats['wins'] . '</td><td class="tiny" align="center">' . $pickRatio . ' (' . $pickPercentage . ')</td></tr>';
break;
case 2:
echo ' <tr' . $rowclass . '><td class="tiny">' . $stats['userName'] . '</td><td class="tiny" align="center">' . $stats['wins'] . '</td><td class="tiny" align="center">' . $pickRatio . ' (' . $pickPercentage . ')</td></tr>';
break;
default: //3
echo ' <tr' . $rowclass . '><td class="tiny"><abbrev title="' . $stats['name'] . '">' . $stats['userName'] . '</abbrev></td><td class="tiny" align="center">' . $stats['wins'] . '</td><td class="tiny" align="center">' . $pickRatio . ' (' . $pickPercentage . ')</td></tr>';
break;
}
$i++;
}
} else {
echo ' <tr><td colspan="3">No weeks have been completed yet.</td></tr><br />';
}
echo '
</table>
</td>
<td>&nbsp;</td>
<td>
<b>By Pick Ratio</b><br />
<table cellpadding="4" cellspacing="0" class="table1">
<tr><th align="left">Player</th><th align="left">Wins</th><th>Pick Ratio</th></tr>';

if (isset($playerTotals)) {
$playerTotals = sort2d($playerTotals, 'score', 'desc');
$i = 0;
foreach($playerTotals as $playerID => $stats) {
$rowclass = (($i % 2 == 0) ? ' class="altrow"' : '');
$pickRatio = $stats['score'] . '/' . $possibleScoreTotal;
$pickPercentage = number_format((($stats['score'] / $possibleScoreTotal) * 100), 2) . '%';
switch ($user_names_display) {
case 1:
echo ' <tr' . $rowclass . '><td class="tiny">' . $stats['name'] . '</td><td class="tiny" align="center">' . $stats['wins'] . '</td><td class="tiny" align="center">' . $pickRatio . ' (' . $pickPercentage . ')</td></tr>';
break;
case 2:
echo ' <tr' . $rowclass . '><td class="tiny">' . $stats['userName'] . '</td><td class="tiny" align="center">' . $stats['wins'] . '</td><td class="tiny" align="center">' . $pickRatio . ' (' . $pickPercentage . ')</td></tr>';
break;
default: //3
echo ' <tr' . $rowclass . '><td class="tiny"><abbrev title="' . $stats['name'] . '">' . $stats['userName'] . '</abbrev></td><td class="tiny" align="center">' . $stats['wins'] . '</td><td class="tiny" align="center">' . $pickRatio . ' (' . $pickPercentage . ')</td></tr>';
break;
}
$i++;
}
} else {
echo ' <tr><td colspan="3">No weeks have been completed yet.</td></tr><br />';
}
echo '
</table>
</td>
</tr>
</table>
<p>&nbsp;</p>';

require_once($boarddir . '/includes/footer.php');


Fog,

  I did not change anything being displayed and only edited it for a php block. The files you are using should be located in the sub folder named includes which can be placed in your main smf directory. The issue I see here is that your going to attempt to pass arrays between files improperly. Those files should have functions that return the necessary values that you assign to an array (or variable).

ie. file named example.php


// this function is in a file called example.php and is located in the SMF board directory
function example_func()
{
   $a = array(0 => 'This is a test!!!', 1 => 'Another test!!!');

  return $a;
}



ie. put in php block:

// in your block code, you call the file and assign the array
global $boarddir;

require_once($boarddir . '/example.php');

$data = example_func();

// let's display the array data for this example
print_r($data);

Fog

There is a weekly entry form that one needs to complete or fill out. That will create results and then standings.  The results have to be manually inputted.

I should show you all the files.

Fog

It kind of works in a PHP Block but it wants you to login and comes up with a blank screen.

Back to the drawing board....

Fog

I see what it wants to do...

http://www.ngsforums.com/fog/phppickem-master/login.php

the reason why it's blank is I don't have the login php file in place and I need to get some css and other stuff in place.

Question...If I put in the login php code in the php block, would one be able to login and navigate within that block to see other pages?  a web site within a block?  Or would an Iframe code work better?

Chen Zhen

#5
Fog,

  I am not sure I understand your question correctly. Would SP pages work for you instead of files?  iframe probably not necessary as one can use cURL or the SMF fetch_web_data($url) function to get a pages data (using cURL to fill a form if necessary). It all depends on what you want to do.

Fog

All I'm trying to do is display the standings of a game I have going on in a SP Block.  Your code works but only if you are logged in and if you're not it takes you to the login page.  Then I got to thinking can I navigate the whole web site I use for the game in a given SP Block...

The iframe idea will work I know but it's not really what I want to do.

I wish I had more knowledge on terms then I'd be able to convey my idea a bit better.

Chen Zhen


Fog,

  The second tiered site that contains the game, requires one to be logged in to view the data? If the second site is also SMF, why do you have it set up to be logged in to view the data if you do not want it that way? I suppose I just do not understand what you are attempting to accomplish.

Fog

QuoteThe second tiered site that contains the game, requires one to be logged in to view the data?

Yes they do...

QuoteIf the second site is also SMF, why do you have it set up to be logged in to view the data if you do not want it that way?

It's not SMF at all....Click Here

What I'd like to do is intergrade this game http://www.phppickem.com/ with SMF or SP Block/Page but I'm testing it as a standalone website.

I thought I would see if I could learn and see if I could display the standings of this game on the standalone site on a SP Block.  However the code that you modified will only work if you are logged on to the standalone site (I'im guessing this is the confusion), other wise the sp block takes you to the login page for the standalone site.

Then I got to thinking if one could navigate the standalone site within the sp block and the iframe idea came to mind.

Chen Zhen


Fog,

  If they have to be logged in to view the data on the other site and you're not able to change that aspect then you must work with that.
You could have them enter a user id and p/w for the game site in their SMF user profile and then use cURL to pass that data which would auto log them in to the game site when they navigate to it.


Fog

I'm thinking if I get rid of this part I don't need to require a login

global $boarddir;
require_once($boarddir . '/includes/application_top.php');

$weekStats = array();
$playerTotals = array();
$possibleScoreTotal = 0;
calculateStats();

require_once($boarddir . '/includes/header.php');

Fog

UD, I'm looking to create a tie breaker input box for the NFL Game I'm hosting.

We want to pick one game per week as a tie breaker.

Total points.

So I'm looking to create an input box that logs a members guess at total points.

Any help would be cool

Fog

Chen Zhen

Fog,

How are you orchestrating this input box?
Is it in a portal block/page or on an existing form?
Do you just want me to create a basic input display and then you do the rest?

If it is an existing form with other inputs you should be able to figure this out on your own.
Just copy one of the existing inputs and change its text (<- prior to input element) and request variable (<- name).
The type will be text or perhaps number for your purposes.

ref. http://www.w3schools.com/tags/tag_input.asp

Fog

You raise a good question...

I'm thinking a portal block...a Page would be way cool.

I'm thinking I would use Sunday Night Games.

Members would have an input box that would be logged, then we would need a way to use this info incase he have more than one winner per week.

If I have one winner and guesses 15/16 games right and the next pickers pick 14/16 games right I don't need a tie breaker.  If I have five members tied for the week I'm looking to use the tie breaker.

Week 1: Total Points for Seahawks vs Packer:  [input box here]
Week 2: Total Points for X vs Y: [input box here]

Fog

UD...We're better off trying to get our members to post it and we log it manually at this point.

If I send you the code to the game I'm hosting would you mind looking at it and seeing if there is a way to add a tie breaker?