0

所以我一直在研究一个小的自动支付系统,我几乎完成了!我的客户在付款后会自动升级他们的帐户,但我有一个小问题。

我目前正在手动将他们的用户名添加到一个数组中,该数组会更改他们的用户名样式以区分他们的等级。

我想知道如何让它检索并成功进入一个数组,然后调用该数组并显示他们的新用户名。

这是我检索用户名然后放入数组的代码:

$db = new mysqli("localhost", "changed", "changed", "changed")or die(mysqli_error());
$listmembers = $db->query("SELECT * FROM members")or die(mysqli_error());

$names = array();
while($listnames = $listmembers->fetch_assoc()) {
$names[] = "'" . $listnames['username'];
}
$newname = explode("\", ", $names);

好的,这就是我的数组代码的样子

$members = 数组($newname);

这是改变他们等级的代码:

if(in_array(strtolower($rows['received']), $members)) { $user = " " 。ucfirst($rows['received']) 。" "; }

如果有人冷帮助我,我将不胜感激。

4

2 回答 2

0

打开警告以查看您的一些错误。

$db = new mysqli("localhost", "changed", "changed", "changed")or die(mysqli_error());
$listmembers = $db->query("SELECT * FROM members")or die(mysqli_error());

$names = array();
while($listnames = $listmembers->fetch_assoc()) {
    $names[] = $listnames['username'];
}

后来是这样的..

if(in_array(strtolower($rows['received']), $names)) {
    $user =  "<font color=\"lime\"><b>" . ucfirst($rows['received']) . "</b></font>";
}
于 2013-02-26T11:58:07.853 回答
0

为什么不直接从数据库中获取数组?

$db = new mysqli("localhost", "changed", "changed", "changed")or die(mysqli_error());
$listmembers = $db->query("SELECT username FROM members")or die(mysqli_error());

$names = $listmembers->fetch_all();

接着:

foreach ( $names as $username ) {
    if ( strtolower($rows['received']) == $username[0] ) {
        $user = ucfirst($rows['received']);
        break;
    }
}
于 2013-02-26T12:02:14.457 回答