Mysqli data_seek error

Using the below code to retrieve to max ring number

<?php $conn = new mysqli(`localhost`,`webuser`,`xxxxxxx`,`show_be`); if ($conn->connect_error) { trigger_error('Database connection failed: ' . $conn->connect_error, E_USER_ERROR); } $query = "SELECT `RingNo` FROM `tblweb_results` ORDER BY `RingNo` DESC LIMIT 1"; $result = $conn->query($query); $result->data_seek(0); if($result === false) { trigger_error('Wrong SQL: ' . $query . ' Error: ' . $conn->error, E_USER_ERROR); } else { while($row = $result->fetch_assoc()){ echo $row['RingNo'] . '
'; }

}

?>

However I get the following error and I can’t find anything about on the net.

Fatal error: Call to a member function data_seek() on boolean in D:\xampp\htdocs\db\connect.php on line 10

Can anyone see what’s causing this please? The query works find in phpMyAdmin.

There is no function data_seek defined in that page. As the error describes.

Hi Howard2, welcome to the forum,

For PHP, try searching the PHP documentation. eg.
http://php.net/manual/en/mysqli-result.data-seek.php

Return Values

Returns TRUE on success or FALSE on failure.

* hint, compare your code to the examples. See a difference?

Also, I don’t know if it really makes things significantly more efficient.,
But
MAX(field)
equuates to
ORDER BY field DESC LIMIT 1

Thanks guys.

Mittineague, I was using Max() as I used to with mysql but when looking around during my code problems I read somewhere that for mysqli I couldn’t use it so changed it to see if the problem fixed itself.

What threw me was couldn’t find any reference on the net for particular error. So many thanks and I will do some more research on the data_seek function.

Cheers for now.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.