0
$content_mysql = mysql_query("SELECT id, content FROM articles ");

I want to save content from mysql to an array, like:

// In the database table:

id: 1 content: oxigen

id: 2 content: hidrogen

//In the php array

echo $array['1']; //It is says: oxigen

echo $array['2']; //It is says: hidrogen
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
Marfi333
  • 15
  • 3
  • 2
    ***Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php).*** [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Oct 20 '16 at 18:43
  • Welcome to Stack Overflow! You can take the [tour] first and learn [ask] a good question. That makes it easier for us to help you. – Katie Oct 20 '16 at 19:04

1 Answers1

0
$content_mysql = mysql_query("SELECT id, content FROM articles ");

$array = [];

while ($row = mysql_fetch_assoc($content_mysql)) {
    $array[(string)$row['id']] = $row['content'];
}
jakub wrona
  • 2,212
  • 17
  • 17