因为我是php的新手。我需要朋友的帮助。所以我发布了问题
我从数据库中检索了数据,并且像这样提取数据。
Country Cricketers ball
INDIA DHONI 45
Raina
ASHWIN
NZ VETTORI 20
BOND
AUS WATSON 10
WARNE
BAN HASAN 100
但是我必须在特定的球队中平分球柱,就像它必须在下面显示我一样
Country Cricketers ball
INDIA Dhoni 15 //Above table 45 has divided for 3 players so 15 each
Raina 15
Ashwin 15
NZ VETTORI 10 //Above table 20 has divided for 2 players so 10 each
BOND 10
AUS WATSON 5 //Above table 10 has divided for 2 players so 5 each
WARNE 5
BAN HASAN 100 //Above players has only one player so 100 remains same
我的代码就像这样
$name = $row["country_name"];
$replace_players = preg_replace('/,/', '<br/>', $cricket_names);
$ball = $row["ball"]; // i am extracting from database
<tbody>
<td>'.$name."<br>".'</td>
<td>'.$replace_players."<br>".'</td>
<td>'.$ball."<br>".'</td> // i have to change it here such that it will distribute dynamically
<td>'.____________________.'</td>
</tr>';
请帮我解决这个问题
答案 0 :(得分:0)
我想要你的东西
$name = $row["country_name"];
$cricket_names = $row["cricket_names"];
$ball = $row["ball"];
$arr_players = explode(",", $cricket_names);
$player_count = sizeof($arr_players);
$each_ball = floor($ball/$player_count);
for($i=0; i<$player_count; $i++)
{
echo '<tr>';
echo '<td>'.$name.'</td>';
echo '<td>'.$arr_players[$i].'</td>';
echo '<td>'.$each_ball.'</td>';
echo '</tr>';
}