php - Parse sql response to array -
sql response seems this: name|locality|date|address. rows can contains same name, locality , date, addres changed every time. so, need put response array this:
[0] => 'name':'...', 'locality':'...', 'date':'...', 'address': [0] => '...', [1] => '...', [2] => '...', ... ...
i have tryed use code, does't work =(
while($r = mysqli_fetch_assoc($q_res)){ $i = 0; if(!in_array($r['watcher_name'], $daily_quests)){ $daily_quests[$i]['name'] = $r['name']; $daily_quests[$i]['date'] = $r['date']; $daily_quests[$i]['locality'] = $r['locality']; } else{ $daily_quests['address'] = $intrnal_addr[$i => $r['address']]; } }
try :
//initialisation $name = ''; $daily_quests = array(); $i = -1; while($r = mysqli_fetch_assoc($q_res)){ //if row different precedent if (strcmp($r['name'], $name) != 0) { $i++; $name = $r['name']; $daily_quests[$i] = array(); $daily_quests[$i]['name'] = $r['name']; $daily_quests[$i]['date'] = $r['date']; $daily_quests[$i]['locality'] = $r['locality']; $daily_quests[$i]['address'] = array(); } // each row, must add address $daily_quests[$i]['address'][] = $r['address'] }
however, suppose name unique. it's more safe compare id.
Comments
Post a Comment