Jump to content

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

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]
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. :)
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.