echo中显示mysql数据库中的随机用户名

voase2hg  于 2021-06-25  发布在  Mysql
关注(0)|答案(3)|浏览(209)

这个问题在这里已经有答案了

我可以在php中混合mysql api吗(4个答案)
两年前关门了。
我想问一下如何在php echo中显示mysql中的数据库用户名

$send = $database->query('SELECT * FROM `usernames` ORDER BY RAND() LIMIT 1');
while ($show = mysql_fetch_array($send)) {
    echo ''.$show['usernames'];
}
qcuzuvrc

qcuzuvrc1#

$sql = "SELECT * FROM 'usernames` ORDER BY RAND() LIMIT 1' ";
$result = $conn->query($sql);
while($record = mysqli_fetch_array($result)) {
foreach ($record as $d){
echo $d;
    }
   }
6tr1vspr

6tr1vspr2#

试试这个

$query = "SELECT * FROM `usernames` ORDER BY RAND() LIMIT 1"
$send = mysql_query($query);
while ($show = mysql_fetch_array($send)) {
    echo ''.$show['usernames'];
}
ujv3wf0j

ujv3wf0j3#

这将修复php错误:

$ts = $database->query('SELECT * FROM `usernames` ORDER BY RAND() LIMIT 1');
while ($show = $ts->fetch(PDO::FETCH_ASSOC)) {
    echo ''.$show['usernames'];
}

为了完整性,您只希望得到一行结果,因此while循环可能是多余的:

$ts = $database->query('SELECT * FROM `usernames` ORDER BY RAND() LIMIT 1');
$show = $ts->fetch(PDO::FETCH_ASSOC);
echo $show['usernames'];

相关问题