Hello. Such a problem, I upload ads from the server, including the paths to the images. I will explain the essence, I send a request to the server, it forms a list of ads in the current category and I try to create an array already in the current array img_name[] . Before adding rows to an array, I create a query in the database ( если 'id_ads равен $row['id'], то добавить строку . Rows are added, but also those that do not fit my condition are added. Ie, for example, I I pull out the image paths for the ad with id=233 , in the base of which there are 2 photos (paths), and in the ad with id=234 , 1 photo (path), then in the response from the server I get the paths to the pictures I don't need for each ad. :
"id": "234", "user_id": "1", "img_name": [ "1_img.jpg" --- id_ads == 234 ] "id": "233", "user_id": "1", "img_name": [ "1_img.jpg", --- id_ads == 234 !!!! - откуда? "2_img.jpg", --- id_ads == 233 "3_img.jpg" --- id_ads == 233 ] In general, I will attach the screenshots more, explained as I could. Help me please. Here is the server function
function adsLoading($cat) { $sql = mysql_query('SELECT * FROM `ads` WHERE `new_ads` = "0" AND `cat` = '.$cat.' ORDER BY `id` DESC'); if(mysql_num_rows($sql) > 0) { while($row = mysql_fetch_array($sql)) { $id = $row['id']; $data['id'] = id; $user_id = $row['user_id']; $data['user_id'] = $user_id; $picAds = mysql_query('SELECT * FROM `upload_img_ads` WHERE `user_id` = 1 AND `temp` = 0 AND `id_ads` = '.$id.''); if(mysql_num_rows($picAds) > 0) { while($img = mysql_fetch_array($picAds)) { $image = $img['img_name']; $id_ads = $img['id_ads']; $data['img_name'][] = $image; } } $vrl['data'][] = $data; } } else { $data['id'] = 0; $vrl['data'][] = ""; } exit(json_encode(array("data" => $vrl['data']))); } The screenshot shows that in the array with id = 232, somehow miraculously adds data that does not belong to this id, despite the fact that in the sample condition this is indicated.


$data = array();in the right place will solve all ( no ) your problems. - vp_arth