各位新人大家好,
我正在承担一项繁琐的任务,即更改游戏的一堆 ID 并将它们转换为字符串。正如你在这里看到的,我对 ID 29 执行了此操作,并将其变成 Sharpshooter。有没有更有效的方法让我做到这一点?或者我是否还要写 100 个以上的 if 案例?
if ($rows[1] == 29)
{
$rows[1] = substr_replace("29","Sharpshooter",0);
}
下面是我的完整代码,我还添加了一些我正在讨论的示例。
<?php
/* Link DB */
include_once 'config.php';
/* Initialize Connection */
$conn=sqlsrv_connect($serverName, $conn_array);
if ($conn){
}else{
die;
}
/* Prepare Statement Preparation */
$sql = "
SELECT TOP 25 G.CharacterName, G.JobCode, D.PVPWin, D.PVPLose, G.PvPExp, D.PVPGiveUp
FROM PvPRanking as G
INNER JOIN PVPScores as D
ON G.CharacterID = D.CharacterID
ORDER BY RANK() OVER (ORDER BY TotalRank ASC )
";
/* Assign Parameter values. */
$param1 = 1;
$param2 = 2;
// Array requirement for prepare statement.
$procedure_params = array(
array(&$param1, SQLSRV_PARAM_OUT),
array(&$param2, SQLSRV_PARAM_OUT)
);
/* The ACTUAL Prepare Statement */
$stmt = sqlsrv_prepare( $conn, $sql, $procedure_params);
/*Execute*/
sqlsrv_execute($stmt);
/* Variables */
$autoincrement = 0;
echo
'
<tr>
<th>Rank</th>
<th>Name</th>
<th>Class</th>
<th>Wins</th>
<!-- <th>Losses</th>
<th>Experience</th>
<th>Quit</th> -->
</tr>';
// Rank # to increment itself. I.E 1,2,3,4,5,6 etc..
while ($rows=sqlsrv_fetch_array($stmt))
{
$autoincrement++;
{
if ($rows[1] == 29)
{
$rows[1] = substr_replace("29","Sharpshooter",0);
}
if ($rows[1] == 30)
{
$rows[1] = substr_replace("30","Knight",0);
}
if ($rows[1] == 29)
{
$rows[1] = substr_replace("31","Dragon Slayer",0);
}
}
// Echo will spit out the rows and the data.
echo
'
<tr id=io>
<td> '.$autoincrement.' </td>
<b> <td style = "color:#AFA;"> '.$rows[0].' </td> </b>
<td> '.$rows[1].' </td>
<td> '.$rows[2].' </td>
<!-- <td> '.$rows[3].' </td>
<td> '.$rows[4].' </td>
<td> '.$rows[5].' </td> -->
';
}
?>
</table>
元芳怎么了