数组似乎在7个项

时间:2017-04-18 02:51:12

标签: php mysql arrays

我在绘制的桌子上有这种奇怪的行为。当我向数据库添加7个以上的条目以便绘制表格时,它似乎崩溃并且不会绘制任何内容。 7或更少,它工作得很好。

我不知道为什么会这样做???

$strSQL = "
SELECT u.username playername
     , IFNULL(a.avatar,'default.jpg') playeravatar
  FROM add_tournament_repeat_guests p
  JOIN nfojm_users u
     ON p.guestID = u.id
  LEFT 
  JOIN nfojm_comprofiler a
     ON u.id = a.user_id
 WHERE p.parent_id = $tournID
";

$query = mysqli_query($con, $strSQL);

while ($row = mysqli_fetch_array($query)) {  

    if (!in_array($row["playername"], $playernames)) {
        $i=0;
        $indexes[$row["playername"]] = 0;
        $playernames[] = $row["playername"];     
    } else {    
        $indexes[$row["playername"]]++;   
        $i = $indexes[$row["playername"]];
    }  
    if (!in_array($row["playeravatar"], $playeravatars)) {
        $i=0;
        $indexes[$row["playeravatar"]] = 0;
        $playeravatars[] = $row["playeravatar"];     
    } else {    
        $indexes[$row["playeravatar"]]++;   
        $i = $indexes[$row["playeravatar"]];
    }  


  }
    print('<table class="block" style="border:2px solid #999999; width:175px; background-color: aliceblue; margin-top:-7px"><thead><tr><th style="color:white; background-color:#444444; height:35px;"> <h2>Leaderboard</h2> </th></tr></thead><tbody>');

   foreach (array_combine($playeravatars, $playernames) as $playeravatar => $playername) {

   print("<tr><td style='padding-left:8px;' class='block'><h4><img src='http://www.arcadeicons.com/images/comprofiler/" . $playeravatar . "' height='35' width='35' style='border-radius:50%'> " . $playername . "</h4></td></tr>");

 } 

1 个答案:

答案 0 :(得分:0)

public class Trade { @Id @Column(name = "ID") private Long tradeTag; @OneToMany(orphanRemoval=true) @JoinColumn(name="trade") private List<Charge> charges; } public class Charge implements Serializable{ private static final long serialVersionUID = 1L; @Id private String chargeType; @Id @Column(name="TRADE") private Long tradeTag; } $playeravatars有不同的长度,这就是$playernames返回array_combine()而不是预期的组合数组的原因(php.net/array_combine)< / p>

具有不同名称且没有头像的2个用户将在FALSE中生成2行,但在$playernames中仅生成1行 - 这是长度不匹配的原因

您可以更简单地编写代码:

$playeravatars