Jump to content

Archived

This topic is now archived and is closed to further replies.

Mutley

Working out win/loss scores (help)

Recommended Posts

So I made a script that determins if team "York" wins, loses or draws depending on the database.

The problem I have is I want it to do it for all teams with the word "York" in, so "York B" or "York C" it will still work it out. How do I do this? Because at the moment it only works if the value is exactly "York" I want it to do it if it contains.

Heres my code:

[code]if(!is_numeric($scorehome)){
?><span class="notplayed">&nbsp;</span><?
}
else {

if($scorehome == $scoreaway) {
?><span class="draw">Draw</span><?
}
else
{

if($home == York) {
if($scorehome > $scoreaway) {
$home?> <span class="win">Win</span> <?
}
else {
$away?> <span class="loss">Loss</span> <?
}
}

else {
if($away == York) {
if($scorehome < $scoreaway) {
$home?> <span class="win">Win</span> <?
}
else {
$away?> <span class="loss">Loss</span> <?
}
}
}
}
}
[/code]

Share this post


Link to post
Share on other sites
Replace the word York with $team, and if you want numerous dynamic teams I would use a mysql database to store the information.

Share this post


Link to post
Share on other sites
So:

[code]$team = York
.$team = York B
.$team = York C[/code]
etc'

Before the code?

Share this post


Link to post
Share on other sites
Is there no way to do anything that CONTAINS "York", so I don't have to keep typing them out?

Share this post


Link to post
Share on other sites
strpos()

[code]
<?php
$teams = array ('York', 'Leeds', 'York A', 'Bradford', 'York B');

foreach ($teams as $team) {
    if (strpos($team,'York') !== false) {
        echo $team . '<br />';
    }
}

?>
[/code]

Share this post


Link to post
Share on other sites
Thanks Barand, so would the final result be this:

[code]
foreach ("York" as "York") {
    if (strpos('York') !== false) {

if(!is_numeric($scorehome)){
?><span class="notplayed">&nbsp;</span><?
}
else {

if($scorehome == $scoreaway) {
?><span class="draw">Draw</span><?
}
else
{

if($home == York) {
if($scorehome > $scoreaway) {
$home?> <span class="win">Win</span> <?
}
else {
$away?> <span class="loss">Loss</span> <?
}
}

else {
if($away == York) {
if($scorehome < $scoreaway) {
$home?> <span class="win">Win</span> <?
}
else {
$away?> <span class="loss">Loss</span> <?
}
}
}
}
}
?>
[/code]

Share this post


Link to post
Share on other sites
I've tried using it as the examples show in the manual but no luck.

Should

strpos("York")

Not work? As in, if it is "York" or contains "York"?

Share this post


Link to post
Share on other sites
strpos takes at least 2 arguments
[code]
if (strpos($haystack, $needle) !== false)
[/code]

ie search the haystack and see if it contains a needle

Share this post


Link to post
Share on other sites
Aha, I understand now, got it to work, I used this:

[code]if(!is_numeric($scorehome)){
?><span class="notplayed">&nbsp;</span><?
}
else {

if($scorehome == $scoreaway) {
?><span class="draw">Draw</span><?
}
else
{
if (strpos($home, York) !== false) {
if($scorehome > $scoreaway) {
$home?> <span class="win">Win</span> <?
}
else {
$away?> <span class="loss">Loss</span> <?
}
}

else {
if (strpos($away, York) !== false) {
if($scorehome < $scoreaway) {
$home?> <span class="win">Win</span> <?
}
else {
$away?> <span class="loss">Loss</span> <?
}
}
}
}
}
[/code]

Thanks alot Barand. :)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.