Home > Backend Development > PHP Tutorial > 請問一這種陣列要怎么充值

請問一這種陣列要怎么充值

WBOY
Release: 2016-06-13 10:48:08
Original
835 people have browsed it

請問一這種陣列要如何充值?
請教大家,有一個陣列,想從資料表取出值來填入,要怎麼改呢?

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$sql = "select sid,township from tbl_township where pid=1";$res = db_query($sql);            while (list($sid,$township)=mysql_fetch_row($res)):       endwhile; 
Copy after login


陣列型式如下:
PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$provinces = array(array('sid' => 'bj', 'township' => 'Beijing'),array('sid' => 'hb', 'township' => 'Hubei'));
Copy after login


------解决方案--------------------
while($row = mysql_fetch_assoc($res)) {
$provinces[] = $row;
}
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template