How to query mysql php one-dimensional array
Today, I will talk to you about how to query the one-dimensional array of mysql php. Many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.
Mysql php query one-dimensional array method: 1, through the "mysql_connect" function to connect to the database; 2, through the "mysql_query" query; 3, the use of "mysql_fetch_assoc" function to return the array.
This article operating environment: Windows7 system, PHP7.1, Dell G3 computer.
How does mysql php query one-dimensional arrays?
Specific problem description:
How does PHP fetch an one-dimensional array from the database
Just want to take out the name of the game and change it to an one-dimensional array of $con = mysql_connect ('localhost',' root', 'root'); mysql_select_db ("php", $con); $result = mysql_query ("SELECT * FROM `game`"); $data_name [] = array (); while ($rs = mysql_fetch_assoc ($result)) {$data_name [] = $rs [' name']; / this is a two-dimensional array} = this is a two-dimensional array. Array ([0] = > Array () [1] = > League of Legends [2] = > DNF [3] = > Longzhigu) how to take one dimension?
Solution:
The code is as follows:
$con = mysql_connect ('localhost',' root', 'root'); mysql_select_db ("php", $con); $result = mysql_query ("SELECT * FROM `game`"); $data_name=array (); / / modified while ($rs = mysql_fetch_assoc ($result)) {$data_name [] = $rs [' name'];} print_r ($data_name) / / after reading the above content, do you have any further understanding of how to query the mysql php one-dimensional array? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.