0

I have to use a php function to manage some data from a db, but i get a Fatal Error on the line where I call mysqli_fetch_array().

    $request = "SELECT Post.* FROM Post WHERE IdUseFk = '".$user_idPk."';";
    $result  = mysqli_query($CONN, $request)
        or die ("<font color='red'>Error: ".mysqli_error($CONN)."</font>");
    $num = mysqli_num_rows($result);

    if ($num == 0) {echo "NOTHING TO DO HERE";}
    else
    {    
        for ($i=1; $i<=$num; $i++)
        {
            $row = mysqli_fetch_array($result, MYSQLI_ASSOC);  //<<-- ERROR ON THIS LINE

            /*...Some other code...*/
        }

    } 

I get this: Fatal error: in C:\xampp\htdocs\Work\load_data.php on line 137

Any suggestion?

EDIT: PROBLEM SOLVED

I can't believe it. For some reason the 'space' chars I put before and after the '=' char in $row = mysqli_fetch_array()

weren't real spaces but another special char that is blank in most editors but php read as part of the function name. I was able to see it thanks to the editor in cpanel. Now it works

GoldenDragon
  • 9
  • 1
  • 4
  • 1
    What is line 137 in load_data.php ? – Jonathan Jun 05 '15 at 23:11
  • Your question gives no insights into what the actual issue is. The code you have is right. A more likely scenario is that you have something up with your setup or some other code. Attach a debugger and post your log. – Dr.Knowitall Jun 05 '15 at 23:12
  • I've found this in the xampp php error log: PHP Fatal error: Call to undefined function  mysqli_fetch_array() in C:\xampp\htdocs\Work\load_data.php on line 137. I am a bit scared now o.o – GoldenDragon Jun 05 '15 at 23:25
  • What version of PHP are you running? I can't imagine mysqli_fetch_array being missing and mysqli_query not... – Devon Bessemer Jun 05 '15 at 23:39
  • Have a look at this posts, that may help you. http://stackoverflow.com/questions/11664536/fatal-error-call-to-undefined-method-mysqli-resultfetch-all – Rizaldi Maulidia Jun 05 '15 at 23:43
  • @RizaldiMaulidia, that is only fetch_all that requires mysqlnd. fetch_array shouldn't need it. – Devon Bessemer Jun 05 '15 at 23:45

1 Answers1

0

Try using a while loop, and you also had an error in your SQL syntax.

$request = "SELECT Post.* FROM Post WHERE IdUseFk = '$user_idPk'";
$result = mysqli_query($CONN, $request)
     or die ("<font color='red'>Error: ".mysqli_error($CONN)."</font>");
$num = mysqli_num_rows($result);

    if ($num == 0) { 
        echo "NOTHING TO DO HERE";
    }  else {    
        while($row = mysqli_fetch_array($result) {
           /*...Some other code...*/     
        }
    } 
OllyBarca
  • 1,501
  • 1
  • 18
  • 35
  • Try again with my edit. I think you had a syntax error in your query. – OllyBarca Jun 05 '15 at 23:37
  • And ditch the for loop, the while loop will loop through however many rows you are retrieving in your query. – OllyBarca Jun 05 '15 at 23:40
  • This isn't the issue. The while loop is unnecessary. Either way would work fine. The issue is something with their PHP install if you see the error undefined function mysqli_fetch_array. – Devon Bessemer Jun 05 '15 at 23:40