Hello, please help with the problem of writing to the data array from mysql. When outputting an array declared as a result of a sample, such duplicates are obtained from the database.

<?php $connection = mysql_connect("localhost","root",""); $db = mysql_select_db("lightside_db"); mysql_set_charset("utf8"); if(!$connection || !$db){ exit(mysql_error()); } $result = mysql_query("SELECT id, title, image, date, author FROM news ORDER BY date"); $arr = mysql_fetch_array($result); foreach ($arr as $key => $value) { echo $key." => ".$value."<br>"; } ?> 

But the code itself

    1 answer 1

    In the function mysql_fetch_array ($ result); add 2 parameters, like this mysql_fetch_array ($ result, MYSQL_ASSOC). If you do not specify a flag, it will return both numeric and associative keys with a value.

    • Thanks a lot! - Andrei Kazmirovich February
    • In general, it is worth using PDO, mysql and mysqli are morally obsolete) - David
    • I have not even heard of this: s - Andrei Kazmirovich
    • php.net/manual/ru/function.mysql-connect.php Just go to the page - vp_arth