0

如果有人能帮我解决这个问题,那就太棒了,我真的不知道如何解决它,而且我一直在绞尽脑汁(以及书籍和互联网)一段时间,却没有真正了解我需要做什么。我无论如何都不是程序员,纯粹是自学的,所以如果看起来很容易,请接受我的道歉。我已经为一个梦幻联赛足球网站创建了一个数据库,并获得了对结果和表格的正确查询,我只想添加一个查询,显示经理每周的结果,以及从中哪些球员为这些经理得分(没有经理的球队拥有相同的球员),例如:

(表头:周 > 经理 > 支持 > 反对 > 得分手) 2 Manager1 3-0(球员 a 1,球员 b 2) 2 Manager2 1-2(球员 f 1) 2 Manager3 4-1(球员 g 2,球员 x 2)

我正在使用大量的连接来获得我的结果,并且一直在尝试使用嵌套的 foreach 循环,我认为我需要做一个单独的 foreach 循环来遍历每个得分球队的任何球员(即从球员名单中拉出目标大于 0),但结果好坏参半 - 我不需要!

这是我的代码,从索引控制器到显示 foreach 循环的 html。如果有人可以提供帮助或有任何想法,我将不胜感激。

    if (isset($_GET['action']) and $_GET['action'] == 'scorers')
    {
    include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';

    $sql = "SELECT Wk.week as ptsweeks, managers.managerid as ID, managers.manager as Manager, CASE when sum(Wk.goals)>GA.goals then '3' when sum(Wk.goals)=GA.goals then '1' when sum(Wk.goals)<GA.goals then '0' END as PTS, sum(Wk.goals) as F, GA.goals as A, case when Wk.goals>'0' then concat(Wk.name,' ',Wk.goals) end as goalscs 
from weeks2012 as Wk 
    inner join goalsAgainst2012 as GA 
    inner join strikers2012 as ST 
    inner join defences2012 as DEF 
    inner join managers
    on 
    Wk.week = GA.week and
    DEF.managerid = ST.managerid and
    ST.playerid = Wk.playerid and
    DEF.defenceid = GA.defenceid and
    managers.managerid = ST.managerid
    where Wk.week = '$weekWK'
    group by managers.managerid";
    $result = mysqli_query($link, $sql);
    if (!$result)
    {
    $error = 'Error updating submitted article.';
        include $_SERVER['DOCUMENT_ROOT'] . '/includes/error.html.php';
        exit();
    }

    while ($row = mysqli_fetch_array($result))
    {
    $weeks[] = array(
    'table' => array('ptsweeks' => $row['ptsweeks'], 'ID' => $row['ID'], 'Manager' => $row    ['Manager'], 'F' => $row['F'], 'A' => $row['A'], 'PTS' => $row['PTS']), 
'gs' => array('goalscs' => $row['goalscs'])
    );

    }


    include 'scorers_html.php';

}

** from scorers_html.php : 
    <table>
    <?php foreach($weeks as $key => $gls): ?>
    <tr> 
      <td> <?php echo $gls['table']['ptsweeks']; ?> </td>
      <td> <?php echo $gls['table']['Manager']; ?> </td>
      <td> <?php echo $gls['table']['F']; ?> </td>
      <td> <?php echo $gls['table']['A']; ?> </td>
      <td> <?php echo $gls['table']['PTS']; ?> </td>
   </tr>

      <?php foreach($weeks as $key => $gls): ?>
     <tr>
      <td> <?php echo $gls['gs']['goalscs']; ?> </td>
       </tr>
      <?php endforeach; ?>     
     <?php endforeach; ?>

     </table>
4

1 回答 1

0

首先,您有一个语法错误,可以通过查看 Stackoverflow 的语法突出显示来查看。你的第三行需要是

include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';

经过进一步审查,以下行也是不正确的:

include $_SERVER['DOCUMENT_ROOT'] . /includes/error.html.php';

它应该是

include $_SERVER['DOCUMENT_ROOT'] . '/includes/error.html.php';

您需要将所有字符串封装在引号或撇号中。

我建议使用包含语法高亮的代码编辑器,例如 KomodoEdit 或 Netbeans;你会省去很多麻烦。

如果这没有帮助,请发布您遇到的具体错误/问题。

于 2013-03-08T22:16:32.830 回答