-2

伙计们,我正在建立一个足球博彩网站,数据馈送公司在一个单独的列中为我提供主队和客队,以 - 符号分隔。我试图思考它,但变得更加困惑,这就是我所拥有的:

$query = "SELECT * FROM participant_template";
$result = mysql_query($query);
if($result){
    while($row = mysql_fetch_array($result)){
        $teams = $row['teams'];
        // The output of $teams looks like this: Manchester - Chelsea
        $home_team = "Please help me out";
        $away_team = "Please help me out";
    }
}

我如何将它们分为主队和客队。

4

1 回答 1

1

试试看。此解决方案期望团队始终以“-”分隔

// The output of $teams looks like this: Manchester - Chelsea
$teamsArr = explode("-",$teams);
$home_team = trim($teamsArr[0]);
$away_team = trim($teamsArr[1]);

同样,您应该将此问题标记为 PHP,而不是 sql。

于 2013-04-19T19:18:20.487 回答