My array:
$data =
Array (
[0] => Array ( [uid] => 1000017727223 [name] => Ter silika )
[1] => Array ( [uid] => 1000043758095 [name] => Brat elina )
[2] => Array ( [uid] => 1000053432719 [name] => Vl zacu )
[3] => Array ( [uid] => 1000054011767 [name] => Chr ris )
[4] => Array ( [uid] => 1000054595524 [name] => Ter sile )
[5] => Array (
[invt_0] => 1000035804034
[invt_1] => 1000036092866
[invt_2] => 1000001823093
[invt_3] => 1000021462636
[invt_4] => 1000030930386
[page] => 1 ) )
$list = array();
foreach($data as $fl){
$result = mysql_query("SELECT * FROM useri WHERE fb_id = " . $fl['uid']);
while ($row = mysql_fetch_array($result)) {
$list[] = $row;
}
}
我出现了下一个错误:
注意:未定义的索引:第20行/pagination.php中的uid
警告:mysql_fetch_array()要求参数1为资源,第21行的/pagination.php中给出布尔值
第20行:$ result = mysql_query(“SELECT * FROM useri WHERE fb_id =”。$ fl ['uid']); 第21行:while($ row = mysql_fetch_array($ result)){
答案 0 :(得分:0)
mysql_query
会返回布尔值false
。使用mysql_error()
从MySQL获取可读的错误消息。
答案 1 :(得分:0)
并非$data
中的所有项目都有uid
($data['5']
没有uid
)并导致执行此类查询:
SELECT * FROM useri WHERE fb_id =
这是错误
答案 2 :(得分:0)
试试这段代码:
foreach($data as $fl){
$result = @mysql_query(sprintf("SELECT * FROM useri WHERE fb_id='%s'", $fl["uid"]));
if(is_resource($result) && mysql_num_rows($result) >= 1) {
while ($row = mysql_fetch_array($result)) {
$list[] = $row;
}
}
}
尝试问题(由前面的@Farnabaz定义)并非$data
中的每个iteam都有uid
因此我的代码只是一个故障安全方法