[英]Populate an Array with Results from mySql Query
I am having a problem with creating an array from the values received from a mySql query
. 我从
mySql query
接收的值创建数组时遇到问题。 I have the following code but I can't populate the array with the returned values. 我有以下代码,但无法使用返回的值填充数组。 I assume that there is a problem with the
while
statement. 我认为
while
语句有问题。 Can anybody help me out? 有人可以帮我吗?
$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'];
}
change your while loop 改变你的while循环
while($stmt->fetch()) while($ stmt-> fetch())
{ {
$return_arr[] = $firstName; $ return_arr [] = $ firstName;
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.