我正在查询我的 postgres 数据库并获得如下名称和 ID:
$datesQuery = "SELECT date_ridden, id from dates WHERE user_id=$userId"; //query
$theDates = pg_query($db, $datesQuery); //execute query
$dates=array(); //want to use this array to have the key as id and value as date_ridden
我想让我的 $dates 数组以 id 作为键,以 date_ridden 作为值。
目前我正在做以下事情(这不是我想做的):
while( $date = pg_fetch_row($theDates) ){
$dates[]['value'] = $date[1]; //date id is value
$dates[]['label'] = $date[0]; //date (in text form) is the label
}
我觉得这应该是一件非常简单的事情,但由于某种原因无法弄清楚。