我想问一下如何在php echo
中显示来自mysql的数据库用户名 $send = $database->query('SELECT * FROM `usernames` ORDER BY RAND() LIMIT 1');
while ($show = mysql_fetch_array($send)) {
echo ''.$show['usernames'];
}
答案 0 :(得分:0)
修复了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'];
答案 1 :(得分:0)
$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;
}
}
答案 2 :(得分:-1)
试试这个
$query = "SELECT * FROM `usernames` ORDER BY RAND() LIMIT 1"
$send = mysql_query($query);
while ($show = mysql_fetch_array($send)) {
echo ''.$show['usernames'];
}