0
这可能是一个愚蠢的简单问题,但我患脑梗死...我使用SELECT语句从MySQL数据库中提取数据,然后通过WHILE循环循环来推送返回的数据到数组'$ arr',使用下面的代码;将项目添加到PHP数组
$query="SELECT idBaptism as id, baptismDate as eventDate, concat(baptismForename,' ',baptismSurname) as name, churchName, tbLocation.idLocation as locationid, location, clat as lat, clng as lng FROM tbBaptism, tbLocation, tbChurch WHERE tbBaptism.idLocation=tbLocation.idLocation AND tbBaptism.idChurch=tbChurch.idChurch";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
$arr = array();
if($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$arr[] = $row;
}
}
我的问题是我想文本“洗礼”追加到阵列中的每一行的末尾,有什么要做到这一点最简单的方法?例如,下面是使用print_r从上面的代码生成的数组的两行的示例输出;
Array ([0] => Array ([id] => 1 [eventDate] => 1874-03-08 [name] => Henry Stanley [churchName] => St. Leonards [locationid] => 28 [location] => Halwell, Devon, UK [lat] => 50.366001 [lng] => -3.720500)
[1] => Array ([id] => 2 [eventDate] => 1870-11-06 [name] => Valentine Joles [churchName] => St. John The Evangelist [locationid] => 27 [location] => East Horrington, Somerset, UK [lat] => 51.218143 [lng] => -2.600683)
我要添加在每一行上的端值对,如[式]>“受浸” ...
你可以添加示例输出吗? – Thamilan
$ arr [] = $ row。“Baptism”;你需要这个? – Gopalakrishnan
运行一个print_r来显示数组的输出,我得到这个(例2返回数组的行);数组([0] =>数组([id] => 1 [eventDate] => 1874-03-08 [name] => Henry Stanley [churchName] => St. Leonards [locationid] => 28 [location] = >英国德文郡哈尔韦尔[lat] => 50.366001 [lng] => -3.720500)[1] => Array([id] => 2 [eventDate] => 1870-11-06 [name] => Valentine Joles [churchName] =>圣约翰福音传教士[locationid] => 27 [location] => East Horrington,英国萨默塞特郡[lat] => 51.218143 [lng] => -2.600683),但我想手动添加另一个条目最后,比如[type] => Baptism – Gary