我一直在寻找正确的格式来从数据库过滤器创建一个多维数组。我为一个项目使用了一个常用的联系人php包装器,它需要一个确切的格式来加载一组电子邮件地址,名字和姓氏。请参阅下文,了解该类将接受的正确阵列格式:
$contacts = array(
array(
'Email Address' => 'test@test.com',
'First Name' => 'Mike - TEST API',
'Last Name' => 'NULL',
)
);现在的代码如下所示:
West Bronx
Williamsburg
Turtle Bay
Times Square
Southeast Bronx
Sutton
Sunnyside
Sheridan Square
Sheepshead
Roosevelt
Riverdale
Ridgewood
Richmond Hill
Battery Park City Network
Yorkville
// Get the value of the filters and see if there are more then one selection
$foo = $_GET['networks'];
$sQuery = "";
if (sizeof($foo) > 0) {
for ($i=0;$i
$sQuery .= "Network LIKE '%$foo[$i]%' OR ";
}
}
else{
$sQuery = "Network LIKE '%$foo[0]%";
}
mysql_select_db($database_conn, $conn);
$query_Recordset0 = "SELECT * FROM contacts WHERE $sQuery ";
// Knock the last "OR" off the Query
$query_Recordset1 = substr($query_Recordset0, 0, -4);
echo $query_Recordset1;
$Recordset1 = mysql_query($query_Recordset1, $conn) or die(mysql_error());
?>
Network | |||
<?php echo $row_Recordset1['Network']; ?> | <?php echo $row_Recordset1['Email']; ?> | <?php echo $row_Recordset1['First Name']; ?> | <?php echo $row_Recordset1['Last Name']; ?> |
//BUILD The Multidimensional Array from the database Query and store it appropriately
$newarray = array();
$newarray[]['Email Address']=$row_Recordset1['Email'];
$newarray[]['First Name']='NULL';
$newarray[]['Last Name']='Last Name';
print_r($newarray);这会产生这样的数组:
Array (
[0] => Array ( [Email Address] => )
[1] => Array ( [First Name] => NULL )
[2] => Array ( [Last Name] => Last Name ) )
Array (
[0] => Array ( [Email Address] => silverslammer@aol.com )
[1] => Array ( [First Name] => NULL )
[2] => Array ( [Last Name] => Last Name ) )
Array (
[0] => Array ( [Email Address] => shlomi@lmopticaldisc.com )
[1] => Array ( [First Name] => NULL )
[2] => Array任何帮助将不胜感激。
以下是我需要的样子:
$contacts = array(
array(
'Email Address' => 'test@test.com',
'First Name' => 'Mike - TEST API',
'Last Name' => 'NULL',
)
);