Home >Backend Development >PHP Problem >How to query one-dimensional array in mysql php
Mysql PHP method of querying one-dimensional arrays: 1. Connect to the database through the "mysql_connect" function; 2. Query through "mysql_query"; 3. Use the "mysql_fetch_assoc" function to return the array.
#The operating environment of this article: Windows7 system, PHP7.1, Dell G3 computer.
How does mysql php query a one-dimensional array?
Specific problem description:
How does PHP retrieve a one-dimensional array from the database
只想取出游戏的名称,变为一维数组$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']; //这是一个二维数组}===============这样是一个二维数组。Array ( [0] => Array ( ) [1] => 英雄联盟 [2] => DNF [3] => 龙之谷 )怎么取一维呢?
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();//有修改 while($rs = mysql_fetch_assoc($result)){ $data_name[] = $rs['name']; } print_r($data_name);//是你要的
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to query one-dimensional array in mysql php. For more information, please follow other related articles on the PHP Chinese website!