-1
 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;
        }
    }

I appears the next error:

Notice: Undefined index: uid in /pagination.php on line 20

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /pagination.php on line 21

line 20:$result = mysql_query("SELECT * FROM useri WHERE fb_id = " . $fl['uid']); line 21:while ($row = mysql_fetch_array($result)) {

3 Answers3

0

mysql_query returns a boolean false if it encounters an error. Use mysql_error() to get a readable error message from MySQL.

Dr. McKay
  • 2,441
  • 2
  • 13
  • 18
0

not all items in $data has uid ($data['5'] dose not have uid ) and it cause to execute query like this:

SELECT * FROM useri WHERE fb_id = 

and this is error

Farnabaz
  • 3,980
  • 1
  • 20
  • 42
0

try this code:

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;
       }
    }
}

try problem is (as defined by @Farnabaz earlier) that not every iteam in $data has uid therefore my code is just a fail-safe method

Sidstar
  • 377
  • 2
  • 6