Pregunta

I am trying to move to the next record in my record set in PHP but am having some trouble with it.

This is what is at the top of my page to set my record set.

  $result = mysqli_query($con,"SELECT * FROM Item WHERE Item.ID = '$x'")or die(mysql_error());    
  $row = mysqli_fetch_array($result) ?>

Further down the page I move to the next record using the below code.

  $row->movenext();

However the line above is causing the error below and I am unsure as to why as it is clearly defined at the top of the page.

Fatal error: Call to a member function movenext() on a non-object 

ALSO: If I call from the record set using $row like I have below it works fine and returns whatever is on the first row.

echo $row['Item_IMAGE'];

This is my first site in PHP so if I have lost my way somewhere in this please let me know where, Thanks

¿Fue útil?

Solución

According to PHP mysqli_fetch_array how to go to next row?, you can just do

$row = mysqli_fetch_array($result));

to get the next row (and with while (($row = mysqli_fetch_array($result))==true){..} you can do something with all rows..)

Otros consejos

its next_result() not movenext()

$row->next_result();

also mysqli_fetch_array does not return object, it returns array. if you try to use OOP then you should use object oriented style of mysqli commands

$db = new Mysqli($host, $user, $password, $database, $port, $socket);
$db->query("some query");
$db->next_result();
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top