donqh00404 2014-01-04 08:08
浏览 32
已采纳

根据用户数量,在字符串中用“,”或“和”分隔用户名

$playernothing = 0;
$sortdrawmax = max($p1count,$player2count,$player3count,$player4count,$player5count,$player6count,$player7count);
$sortdraww = mysql_query("SELECT username,count FROM blackjackmultijoin WHERE gameid = '$gameid' AND count = '$sortdrawmax'");
while($sortdraw = mysql_fetch_array($sortdraww)){
$playernothing++;
$playersname.$playernothing = $sortdraw['username'];
}

if($sortdrawmax < 1){ 
   $drawoutcome = "All users <b>busted</b> and the game will restart in <b>$gamedrawleft</b> seconds..."; 
}
elseif($playernothing == 2){ 
   $drawoutcome = "$playersname1 and $playersname2 drew with <b>$sortdrawmax</b>! Game will restart in <b>$gamedrawleft</b> seconds..."; 
 }
elseif($playernothing == 3){ 
   $drawoutcome = "$playersname1, $playersname2 and $playersname3 drew with <b>$sortdrawmax</b>! Game will restart in <b>$gamedrawleft</b> seconds..."; 
}

I have the above code in a part of my Multiplayer Blackjack script.
My intentions is a code that will complete the $drawoutcome above so that for each user which has the highest amount in a draw are seperated by a comma with the last name coming after "and".

Can anyone please help with the correct way of doing this?

  • 写回答

2条回答 默认 最新

  • dqcj32855 2014-01-04 08:21
    关注
    $playernothing = 0;
    $sortdrawmax = max($p1count,$player2count,$player3count,$player4count,$player5count,$player6count,$player7count);
    $sortdraww = mysql_query("SELECT username,count FROM blackjackmultijoin WHERE gameid = '$gameid' AND count = '$sortdrawmax'");
    while($sortdraw = mysql_fetch_array($sortdraww))
    {
        $playernothing++;
        $arr[] = $playersname.$playernothing = $sortdraw['username'];
    }
    if(count($arr) > 1)
    {
        $last = $arr[count($arr)-1];
        unset($arr[count($arr)-1]);
        $usernames = implode(",", $arr)." and {$last}";
    }
    else
        $usernames = implode("", $arr);
    if($sortdrawmax < 1)
    { 
       $drawoutcome = "All users <b>busted</b> and the game will restart in <b>$gamedrawleft</b> seconds..."; 
    }
    elseif($playernothing == 2)
    { 
       $drawoutcome = "$usernames drew with <b>$sortdrawmax</b>! Game will restart in <b>$gamedrawleft</b> seconds..."; 
    }
    elseif($playernothing == 3)
    { 
       $drawoutcome = "$usernames drew with <b>$sortdrawmax</b>! Game will restart in <b>$gamedrawleft</b> seconds..."; 
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥100 IED中交流采样通道、以及程序流程的设计
  • ¥15 我如果只想表示节点的结构信息,使用GCN方法不进行训练可以吗
  • ¥15 GPTs营销指令提示词和创建方案
  • ¥15 QT6将音频采样数据转PCM
  • ¥15 本地安装org.Hs.eg.dby一直这样的图片报错如何解决?
  • ¥15 下面三个文件分别是OFDM波形的数据,我的思路公式和我写的成像算法代码,有没有人能帮我改一改,如何解决?
  • ¥15 Ubuntu打开gazebo模型调不出来,如何解决?
  • ¥100 有chang请一位会arm和dsp的朋友解读一个工程
  • ¥50 求代做一个阿里云百炼的小实验
  • ¥15 查询优化:A表100000行,B表2000 行,内存页大小只有20页,运行时3页,设计两个表等值连接的最简单的算法