我有以下代码选择MYSQL中的所有行,但它只显示最后一行
dictionary_file=set(words_from_file("big_word_list.txt"))
答案 0 :(得分:1)
Your code echo last row because, within while
loop every time you overwrites $token
value with new value. Try to connect using PDO&像这样将变量赋给数组。
$token=[];
$user='your_user_name';
$pass='your_password';
$conn= new PDO('mysql:host=your_host_name;dbname=your_db_name', $user, $pass);
$query = $conn->prepare('SELECT * FROM `users`');
$query->execute();
// alternatively you could use PDOStatement::fetchAll() and get rid of the loop
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
$token[] = $row['instagram_access_token']; // see this line with []
}
echo '<pre>';
print_r($token);
echo '</pre>';
注意:请勿使用 mysql _ * 在此处查看更多内容Why shouldn't I use mysql_* functions in PHP?
答案 1 :(得分:-1)
将您的代码更改为:
$query = mysql_query("SELECT * FROM `users` ORDER BY RAND()") or
die(mysql_error());
while ( $row = mysql_fetch_assoc($query) )
{
$m = $row['instagram_access_token'];
echo "$m";
}