我通過mySQL製作了一個簡單的查詢系統,它向我展示了100條記錄,並將它們提取到我的遊戲中,但我用PHP中的代碼獲得了probelm。我想要使用標籤空間(\t\t\t\t\t
),但我有這個當前系統的問題(例如,如果我有字段與兩個不同的字符串值10char和2char然後使用選項卡空間,使它們之間的空間,我得到不同的結果:標籤空間問題
2Char string + 5char space = 7Char
和10Char string + 5Char space = 15Char
$query = "SELECT * FROM `scores` ORDER by `score` DESC LIMIT 100";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$num_results = mysql_num_rows($result);
for($i = 0; $i < $num_results; $i++)
{
$row = mysql_fetch_array($result);
echo $i+1 . "-" . "\t\t Name: " .$row['name'] . "\t\t\t\t Device: " . $row['device'] . "\n \t\t Difficulty: " . $row['level']. "\t\t\t\t Score: " . $row['score'] . "\n\n";
}
代碼輸出
1- Name: James Device: HTC OneX
Difficulty: Hard Score: 5760
2- Name: Erika_S Device: PC
Difficulty: Normal Score: 13780
...
我所需的輸出
1- Name: James Device: HTC OneX
Difficulty: Hard Score: 5760
2- Name: Erika_S Device: PC
Difficulty: Normal Score: 13780
...
您不應該使用製表符,因爲它們的實際寬度_widely vary_。如果這是一個瀏覽器,你有沒有考慮過使用HTML表格? – Litty
如果您仍然需要使用製表符,請務必在決定要顯示多少製表符之前對文本進行計數。也就是說,如果你不知道製表符將使用多大的尺寸(空間),有時候用空格會更好。我還假設你使用的是等寬字體... – Christian
你知道 和str_repeat嗎? – Oliver