[英]Im only getting one set of result when trying to use mysql_fetch_array()
function GetVideoInfo( $video_id, $user_id )
{
$result = mysql_query("SELECT * FROM `mytable`
WHERE
video_id = '$video_id'
AND
user_id = '$user_id'")
or die( mysql_error() );
return mysql_fetch_array( $result );
}
$videoRecepients = $viddler_custom->GetVideoRecepients( $video_details['id'] );
echo "<pre>";
print_r($videoRecepients);
echo "</pre>"
When I try using print_r, it only results a single row in the table. 当我尝试使用print_r时,它只会在表中产生一行。 My expected result should have 2 results.
我的预期结果应该有2个结果。 I am 100% sure that my query is correct, so that is not the problem.
我100%确定我的查询是正确的,所以这不是问题。 I'm thinking that maybe it's on my mysql_fetch_array that is wrong.
我在想,也许是因为我的mysql_fetch_array错误。
Your help would be greatly appreciated and rewarded! 您的帮助将不胜感激和回报! Thanks!
谢谢! :)
:)
All of the fetch functions will return a single row, you will need to loop until the result is empty like this ( snippet from php.net ). 所有的fetch函数都将返回一行,您将需要循环直到结果为空(如php.net的片段 )。
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
printf("ID: %s Name: %s", $row["id"], $row["name"]);
}
From the example on the manual page, mysql_fetch_array
returns the information on the current pointer of the $result object. 从手册页上的示例中,
mysql_fetch_array
返回有关$ result对象的当前指针的信息。 This will mean you want to loop through the result until you've fetched everything. 这意味着您要遍历结果,直到获取所有内容。
while ($row=mysql_fetch_array($result)) {
$set[] = $row;
}
print_r($set);
You need to put the mysql_fetch_array($result) in a loop 您需要将mysql_fetch_array($ result)放入一个循环中
while($row = mysql_fetch_array($result))
{
// do something with $row
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.