查询为:
如何将manualtab中的缩写提取到数组中。代码:
$connection = mysql_connect('localhost', 'root', '') or die ('Unable to connect!');
mysql_select_db('mydb') or die ('Unable to select database!');
$query = 'SELECT abbr FROM manualtab';
$result = mysql_query($query) or die ('Error in query');
$row = mysql_fetch_row($result);
$array = array();
while ($row = mysql_fetch_row($result))
{
$array[] = $row;
}
如果你的意思是,获取数组中的每个缩写,那么:
$abbr = array();
while ($row = mysql_fetch_row($result))
{
$abbr[] = $row[0];
}
是一种方法。
这就完成了任务,除非你想获取所有值,在这种情况下,你需要循环:
$connection = mysql_connect('localhost', 'root', '') or die ('Unable to connect!');
mysql_select_db('mydb') or die ('Unable to select database!');
$query = 'SELECT abbr FROM manualtab';
$result = mysql_query($query) or die ('Error in query');
$row_list = array();
while($row = mysql_fetch_assoc($result)) {
$row_list[] = $row;
}
var_dump($row_list);
/* row_list now contains:
array(
array( 'abbr' => ... ),
array( 'abbr' => ... ),
array( 'abbr' => ... ),
...
) */