Mutley Posted October 13, 2006 Share Posted October 13, 2006 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"> </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] Quote Link to comment https://forums.phpfreaks.com/topic/23864-working-out-winloss-scores-help/ Share on other sites More sharing options...
tleisher Posted October 13, 2006 Share Posted October 13, 2006 Replace the word York with $team, and if you want numerous dynamic teams I would use a mysql database to store the information. Quote Link to comment https://forums.phpfreaks.com/topic/23864-working-out-winloss-scores-help/#findComment-108439 Share on other sites More sharing options...
Mutley Posted October 14, 2006 Author Share Posted October 14, 2006 So:[code]$team = York.$team = York B.$team = York C[/code]etc'Before the code? Quote Link to comment https://forums.phpfreaks.com/topic/23864-working-out-winloss-scores-help/#findComment-108676 Share on other sites More sharing options...
Mutley Posted October 15, 2006 Author Share Posted October 15, 2006 Is there no way to do anything that CONTAINS "York", so I don't have to keep typing them out? Quote Link to comment https://forums.phpfreaks.com/topic/23864-working-out-winloss-scores-help/#findComment-108999 Share on other sites More sharing options...
Barand Posted October 15, 2006 Share Posted October 15, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/23864-working-out-winloss-scores-help/#findComment-109019 Share on other sites More sharing options...
Mutley Posted October 15, 2006 Author Share Posted October 15, 2006 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"> </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] Quote Link to comment https://forums.phpfreaks.com/topic/23864-working-out-winloss-scores-help/#findComment-109074 Share on other sites More sharing options...
Barand Posted October 15, 2006 Share Posted October 15, 2006 http://www.php.net/foreachhttp://www.php.net/strpos Quote Link to comment https://forums.phpfreaks.com/topic/23864-working-out-winloss-scores-help/#findComment-109086 Share on other sites More sharing options...
Mutley Posted October 16, 2006 Author Share Posted October 16, 2006 I've tried using it as the examples show in the manual but no luck.Shouldstrpos("York")Not work? As in, if it is "York" or contains "York"? Quote Link to comment https://forums.phpfreaks.com/topic/23864-working-out-winloss-scores-help/#findComment-109601 Share on other sites More sharing options...
Barand Posted October 16, 2006 Share Posted October 16, 2006 strpos takes at least 2 arguments[code]if (strpos($haystack, $needle) !== false)[/code]ie search the haystack and see if it contains a needle Quote Link to comment https://forums.phpfreaks.com/topic/23864-working-out-winloss-scores-help/#findComment-109681 Share on other sites More sharing options...
Mutley Posted October 16, 2006 Author Share Posted October 16, 2006 Aha, I understand now, got it to work, I used this:[code]if(!is_numeric($scorehome)){ ?><span class="notplayed"> </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. :) Quote Link to comment https://forums.phpfreaks.com/topic/23864-working-out-winloss-scores-help/#findComment-109731 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.