Jump to content

Working out win/loss scores (help)


Mutley

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]
Link to comment
https://forums.phpfreaks.com/topic/23864-working-out-winloss-scores-help/
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]
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. :)

Archived

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

×
×
  • Create New...

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.