Я пытаюсь получить два значения массива в массиве. У меня есть две ситуации: одна выполнена, а другая – не сделана. Внутри массива я могу получить один массив, но не смог достичь кратных значений, как указано в приведенном ниже ожидаемом выходе.
[{"id":"3","category":"Name","text":"text with some data","image":"http:\/\/examole.net\/folder\/images\/category1.jpg"},{"id":"4","category":"Name","text":"text with some data","image":"http:\/\/examole.net\/folder\/images\/category1.jpg"}]
код с запросом done и notdone
$response = array(); $response2 = array(); if(isset($_REQUEST['action']) && $_REQUEST['action']=='test') { $query="select * from exampledb where id='".$db->escape($_REQUEST['id'])."' and workdone='done'"; $num= $db->num_rows($query); if($num) { $rows = $db->get_results($query); foreach($rows as $k=>$row1) { $response[$k]['id'] = $row1['id']; $response[$k]['category'] = $row1['category']; $response[$k]['text'] = $row1['text']; $response[$k]['image'] = $row1['image']; } } else{ $response['message']='No user Found'; $response['status']='fail'; } $query="select * from exampledb where id='".$db->escape($_REQUEST['id'])."' and workdone='notdone'"; $num= $db->num_rows($query); if($num) { $rows = $db->get_results($query); foreach($rows as $k=>$row1) { $response[$k]['id'] = $row1['id']; $response[$k]['category'] = $row1['category']; $response[$k]['text'] = $row1['text']; $response[$k]['image'] = $row1['image']; } } else { $response['message']='No user Found'; $response['status']='fail'; } echo json_encode($response); echo json_encode($response2); } }
в состоянии$response = array(); $response2 = array(); if(isset($_REQUEST['action']) && $_REQUEST['action']=='test') { $query="select * from exampledb where id='".$db->escape($_REQUEST['id'])."' and workdone='done'"; $num= $db->num_rows($query); if($num) { $rows = $db->get_results($query); foreach($rows as $k=>$row1) { $response[$k]['id'] = $row1['id']; $response[$k]['category'] = $row1['category']; $response[$k]['text'] = $row1['text']; $response[$k]['image'] = $row1['image']; } } else{ $response['message']='No user Found'; $response['status']='fail'; } $query="select * from exampledb where id='".$db->escape($_REQUEST['id'])."' and workdone='notdone'"; $num= $db->num_rows($query); if($num) { $rows = $db->get_results($query); foreach($rows as $k=>$row1) { $response[$k]['id'] = $row1['id']; $response[$k]['category'] = $row1['category']; $response[$k]['text'] = $row1['text']; $response[$k]['image'] = $row1['image']; } } else { $response['message']='No user Found'; $response['status']='fail'; } echo json_encode($response); echo json_encode($response2); } }
в состоянии$response = array(); $response2 = array(); if(isset($_REQUEST['action']) && $_REQUEST['action']=='test') { $query="select * from exampledb where id='".$db->escape($_REQUEST['id'])."' and workdone='done'"; $num= $db->num_rows($query); if($num) { $rows = $db->get_results($query); foreach($rows as $k=>$row1) { $response[$k]['id'] = $row1['id']; $response[$k]['category'] = $row1['category']; $response[$k]['text'] = $row1['text']; $response[$k]['image'] = $row1['image']; } } else{ $response['message']='No user Found'; $response['status']='fail'; } $query="select * from exampledb where id='".$db->escape($_REQUEST['id'])."' and workdone='notdone'"; $num= $db->num_rows($query); if($num) { $rows = $db->get_results($query); foreach($rows as $k=>$row1) { $response[$k]['id'] = $row1['id']; $response[$k]['category'] = $row1['category']; $response[$k]['text'] = $row1['text']; $response[$k]['image'] = $row1['image']; } } else { $response['message']='No user Found'; $response['status']='fail'; } echo json_encode($response); echo json_encode($response2); } }
ожидая выхода
[{Done:{{"id":"3","category":"Name","text":"text with some data","image":"http:\/\/examole.net\/folder\/images\/category1.jpg"},{"id":"4","category":"Name","text":"text with some data","image":"http:\/\/examole.net\/folder\/images\/category1.jpg"} }, Notdone:{{"id":"3","category":"Name","text":"text with some data","image":"http:\/\/examole.net\/folder\/images\/category1.jpg"},{"id":"4","category":"Name","text":"text with some data","image":"http:\/\/examole.net\/folder\/images\/category1.jpg"} }}]