Jump to content


Photo

Working out win/loss scores (help)


  • Please log in to reply
9 replies to this topic

#1 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 13 October 2006 - 04:08 PM

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:

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> <?
		}
		}
		}
		}
		}

~ Mutley.

#2 tleisher

tleisher
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 13 October 2006 - 04:39 PM

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

#3 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 14 October 2006 - 12:46 AM

So:

$team = York
.$team = York B
.$team = York C
etc'

Before the code?
~ Mutley.

#4 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 15 October 2006 - 08:47 AM

Is there no way to do anything that CONTAINS "York", so I don't have to keep typing them out?
~ Mutley.

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 15 October 2006 - 10:52 AM

strpos()

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

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

?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 15 October 2006 - 04:40 PM

Thanks Barand, so would the final result be this:

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> <?
		}
		}
		}
		}
		}
		?>

~ Mutley.

#7 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 15 October 2006 - 05:27 PM

http://www.php.net/foreach
http://www.php.net/strpos
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#8 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 16 October 2006 - 04:13 PM

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"?
~ Mutley.

#9 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 16 October 2006 - 07:00 PM

strpos takes at least 2 arguments
if (strpos($haystack, $needle) !== false)

ie search the haystack and see if it contains a needle
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#10 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 16 October 2006 - 09:14 PM

Aha, I understand now, got it to work, I used this:

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> <?
		}
		}
		}
		}
		}

Thanks alot Barand. :)
~ Mutley.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users