使用mySql Query中的结果填充数组

时间:2017-01-22 02:16:31

标签: php mysql arrays

我遇到了从mySql query收到的值创建数组的问题。我有以下代码,但我不能用返回的值填充数组。我假设while语句存在问题。有人可以帮帮我吗?

$return_arr = array(); 

$searchTerm=$_GET['searchTerm'];
$query = "SELECT Actor.FirstName, Actor.LastName FROM Actors WHERE Actor.ActorFirstName LIKE '%$searchTerm%' ";

$stmt = $db->prepare($query);
$stmt->execute();
$stmt->store_result();
$numrows = $stmt->num_rows;
$stmt->bind_result($firstName, $lastName);

while($row = mysql_fetch_assoc($stmt) {
    $return_arr[] =  $row['FirstName'];
}

1 个答案:

答案 0 :(得分:0)

更改你的while循环

while($ stmt-> fetch())

{

$ return_arr [] = $ firstName;

}