How to query one-dimensional array in mysql php

藏色散人
Release: 2023-03-12 19:08:02
Original
1800 people have browsed it

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

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);//是你要的
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!