php - Adding key to multiple arrays and filling the values for that key in order with the corresponding value from another ordered array -
i have code (below) gets 2 arrays, comma separated list of users have claimed product , corresponding comma separated list of when claimed it. matches user_id users table , gets user info in multiple arrays. want append corresponding claimed_time each of outputted arrays, can't figure out how it.
$q = "select claimed_by, claimed_time post post_id='$post_id' , accepted_user='' , user_id='$id'"; $r = mysqli_query ($dbc, $q) or trigger_error("query: $q\n<br />mysql error: " . mysqli_error($dbc)); if (mysqli_num_rows($r) == 1) { $postrow = mysqli_fetch_array($r,mysqli_assoc); $arr = explode(',', $postrow['claimed_by']); $arr2 = explode(',', $postrow['claimed_time']); $users = array(); $r = mysqli_query($dbc,"select * users id in (".implode(',',$arr).")"); $count=0; while($row = $r->fetch_assoc()){ $multiple_row_result[] = $row; } echo json_encode($multiple_row_result);//result i've tried putting next while loop no success:
$multiple_row_result['claimed_time']=$arr2 i thinking along lines of foreach statement might work, can't work.
thanks.
it easier if restructured table structure.
but in current format, like
while($row = $r->fetch_assoc()){ //get key id array - $arr $key = array_search($row['id'], $arr); //get claimed_time id using $key , add together $row $row['claimed_time'] = $arr2[$key]; $multiple_row_result[] = $row; } php arrays foreach while-loop
No comments:
Post a Comment