我正在做一个小项目,我需要从每一行返回一组值,但只从表中的一列(页面)返回。
我的方法如下所示:
public static function getMainArray() {
$conn = parent::connect();
$sql = "SELECT page FROM " . TBL_PAGES . " WHERE level = 0";
try {
$st = $conn->prepare( $sql );
$st->execute();
$pages = array();
foreach ( $st->fetchAll() as $row ) {
$pages[] = new Page( $row );
}
parent::disconnect( $conn );
return array( $pages);
} catch ( PDOException $e ) {
parent::disconnect( $conn );
die( "Query failed: " . $e->getMessage() );
}
}
当我打印这个数组时,
$pages = array();
$pages = Page::getMainArray();
print_r($pages);
输出如下:
Array (
[0] => Array (
[0] => Page Object ( [data:protected] => Array (
[id] =>
[page] => home
[url] =>
[level] =>
[parent] =>
[nazov] =>
[title_navi] =>
[title_meta] =>
)
)
[1] => Page Object ( [data:protected] => Array (
[id] =>
[page] => about
[url] =>
[level] =>
[parent] =>
.
.
.
我需要改变什么,所以输出将是这样的:
Array (
[0] => home
[1] => about
[2] => orders
[3] => info
[4] => contact
)