CompleteNewbie Posted December 20, 2020 Share Posted December 20, 2020 I'm trying to recreate the code from PHP, mysql, javascript, CSS and HTML from O'reily, but i can't make it work Here's the code I added: $query = "select * from classics"; $result = $connection->query($query); if (!$result) die ("Database access failed: " . $connection->error); $rows = $result->num_rows; for ($j=0; $j < $rows; ++$j) { $result->data_seek($j); $row = $result->fetch_array(MYSQLI_NUM); echo <<<_END <pre> Author $rows[0] Title $rows[1] Category $rows[2] Year $rows[3] ISBN $rows[4] </pre> _END; } Here's the error i receive: Notice: Trying to access array offset on value of type int in /var/www/html/test/mysqlitest.php on line 53 I didn't put all the code because everything else works well, i can connect to mysql and add stuff, but i can retrieve stuff using fetch_array['author'] but fetch_array(MYSQLI_NUM) doesn't work. I've tried things from the web but I've only been doing php for a week so my knowledge is quite limited. Thank you for your time. Quote Link to comment https://forums.phpfreaks.com/topic/311902-mysqli_num-doest-work/ Share on other sites More sharing options...
Barand Posted December 20, 2020 Share Posted December 20, 2020 forget the for() loop. while ($row = $result->fetch_row() ) { echo $row[0]; . . . } Quote Link to comment https://forums.phpfreaks.com/topic/311902-mysqli_num-doest-work/#findComment-1583299 Share on other sites More sharing options...
CompleteNewbie Posted December 21, 2020 Author Share Posted December 21, 2020 i just found the problem 😅 while checking your proposition i realised i wrote $rows with an 's'... Now it works Quote Link to comment https://forums.phpfreaks.com/topic/311902-mysqli_num-doest-work/#findComment-1583304 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.