假设我有一个名为“pcode”的mysql数据库只有一个名为“uk_postcodes”的表,我想用第一列填充我的数组,称为“postcodes”。以下代码缺少什么:
//link to mysql server
$link = mysql_connect('localhost', 'root', 'root');
mysql_select_db('pcode');
$sql = "SELECT * FROM `ukpostcodes`";
$query = mysql_query($sql);
$var = array();
答案 0 :(得分:7)
$sql = "SELECT postcodes FROM ukpostcodes";
$result = mysql_query($sql);
$var = array();
while ($row = mysql_fetch_array($result)) {
$var[] = $row['postcodes'];
}