donte1234567 2012-06-03 20:29
浏览 11

标签空间问题

I made a simple query system through mySQL which is showing me 100 records and I fetch them into my game but I have probelm with the codes in PHP.

I want to have 5char space between each row So I have to use tab space (\t\t\t\t\t), But I have a problem with this current system (e.g If I have field with two diffrent string value 10char and 2char then use tab space to make space between them I get different results:

2Char string + 5char space = 7Char and 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'] . "
 \t\t Difficulty: " . $row['level']. "\t\t\t\t Score: " . $row['score'] . "

";
}

Codes Output

1- Name: James   Device: HTC OneX
  Difficulty: Hard    Score: 5760

2-  Name:  Erika_S      Device: PC
  Difficulty:  Normal       Score: 13780

...

My Desired Output

1- Name: James          Device: HTC OneX
   Difficulty: Hard     Score: 5760

2- Name: Erika_S        Device: PC
   Difficulty: Normal   Score: 13780
...
  • 写回答

2条回答 默认 最新

  • dongxuanjiao0795 2012-06-03 20:41
    关注

    Tab in fact is one char, but displayed in the way that user want. When, for example, in IDE you choose 8 spaces for 1 tab you will get it. There's a fantastic concept called elastic tabstops, but it's only concept - so sad.

    Conclusion: you can't do it what you described with tab.

    What you can do:

    • Calculate needed spaces and hardcode with &nbsp;, but it's dirty and you shouldn't do this.
    • Use html tables
    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line