P
P
Pavel Teplyansky2015-11-17 18:56:32
PHP
Pavel Teplyansky, 2015-11-17 18:56:32

What function should mysql_result be changed to in order for the code to work?

I am learning PHP from Nixon's book, and while typing code from it, the IDE started highlighting some functions as obsolete for me, and I decided to try to rework the code to a more relevant one, but unfortunately I could not cope with the problem that is visible in the screenshot.00ad15c89c484f51b2be9eb1fb1d1531.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Miku Hatsune, 2015-11-17
@Shinyonok

// You have mysql_result() call in the screenshot, and you are using MySQLi Get
a newer book and open the MySQLi documentation )
This is how it should work (simplified version):

<?php
$db = mysqli_connect('localhost', 'user', 'password', 'databaseName');

if ($db->connect_errno)
{
   exit('Не получилось соеденится к MySQL серверу');
}

$query = mysqli_query($db, 'SELECT * FROM `classics`');

while ($row = mysqli_fetch_assoc($query))
{
   echo 'Автор: ',$row['author'];
}
?>

S
shagguboy, 2015-11-17
@shagguboy

mysql_result($query) or die(mysql_error());

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question