带有PHP和MySQL多列的下拉菜单

时间:2017-01-07 16:19:51

标签: javascript php html mysql select

我需要一个包含多列的下拉菜单。选项中的数据来自MySQL使用PHP。这是我的代码

while (true) {
  var  updates = await bot.MakeRequestAsync(new GetUpdates() { Offset = offset });
  foreach(var update in updates) {
    var sender = GetSender(update);
    var game = RetrieveGameOrInit(sender);

    // ... rest of your processing, but your code is a little messy and
    // you have to figure out how to refactor the processing by yourself
    game.Update(update);

    // do something with game, and possibly remove it if it's over.
  }
}


public string GetSender(UpdateResponseOrSomething update)
{
    // use the Telegram API to find a key to uniquely identify the sender of the message.
    // the string returned should be the unique identifier and it
    // could be an instance of another type, depending upon Telegram
    // API implementation: e.g. an int, or a Guid.
}

private Dictionary<string, Game> _runningGamesCache = new Dictionary<string, Game>();

public Game RetrieveGameOrInit(string senderId)
{
    if (!_runningGamesCache.ContainsKey(senderId))
    {
       _runningGamesCache[senderId] = InitGameForSender(senderId);
    }

    return _runningGamesCache[senderId];
}

/// Game.cs
public class Game
{
  public string SenderId { get; set; }
  public string DesiredWord { get; set; }
  // ... etc

  public void Update(UpdateResponseOrSomething update)
  {
    // manage the update of the game, as in your code.
  }
}

这是我的代码输出的样子:

$query = mysql_query("SELECT *FROM accounts");

    <select class="form-dropdown validate[required]" style="width:515px;" id="accountTitleOptions" name="accountTitle-options">
            <option selected value="--- Select Option ---"> --- Select Option --- </option>
            <?php while ($row = mysql_fetch_assoc($query)) { ?>
            <option><?php echo $row['accountTitle'] ?> <?php echo $row['accountNumber'] ?></option>
            <?php } ?>
    </select>

My result

但我想要的是像这样正确组织的下拉列表

Karachi Traders 692700001
Zulfiqar Ahmad 692700002
Mian Sarfaraz 692700003
Malik Younus Commission Shop 692700004
Farhan Ashraf Commission Shop 692700006

我尝试了很多解决方案,但仍然没有给我所需的输出。

1 个答案:

答案 0 :(得分:0)

一种方法(纯文本方法):

  • 使用monospaced font
  • 计算每个项目的字符数
  • 与每个项目连接多个空格,等于(max_no_of_chars - no_of_chars)
  • 然后连接你的号码

希望有所帮助