在PHP中返回带有mysql查询的字符串列表

时间:2017-11-08 11:01:11

标签: php mysql

我试图用PHP做一个简单的查询,它返回一个包含用户所有名字的字符串列表,但我可以弄明白该怎么做。我唯一想到的就是这个:

//You can easy cast it to your type or Convert it.
var _strValue = Sessions["page"].ToString() //if its string 

但这会返回一个JSon,蚂蚁想法如何做到这一点?

1 个答案:

答案 0 :(得分:2)

<?php

$host_name  = "hostname";
$database   = "database";
$user_name  = "username";
$password   = "pass";

$connect = mysqli_connect($host_name, $user_name, $password, $database);

$select = "SELECT username from userstasker";

$result = $connect->query($select);
$usernames = array();

while($r = mysqli_fetch_assoc($result)) {
    $usernames[] = $r["username"];
}

$connect->close();

// Do something with $usernames

?>