Home  >  Article  >  Backend Development  >  How to query one-dimensional array in mysql php

How to query one-dimensional array in mysql php

藏色散人
藏色散人Original
2021-09-20 09:50:381865browse

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.

How to query one-dimensional array in mysql php

#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] => 龙之谷 )怎么取一维呢?

How to query one-dimensional array in mysql php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn