$newtotal = searcharray($fieldname, 'groupid', $numbers, 'total'); $memberstatus = memberstatus($fieldname); $result_r[] = array('reason' => 'change', 'dataid' => $fieldname, 'newvalue' => $newtotal, 'status' => $memberstatus); } if (!empty($gene_query)) { $query2 = mysql_query("SELECT groupid, groupname, co_id, groupimg FROM groups WHERE groupid IN( " . $gene_query . " ) " . $gene_query1 . " ORDER BY groupid DESC") or die("Database query has failed1: " . mysql_error()); while ($row = mysql_fetch_array($query2)) { $groupimg = 'uploaded_files/groupimgs/thumbs/' . $row['groupimg']; $groupname = $row['groupname']; $groupid = $row['groupid']; if ($row['co_id'] == $_SESSION['user_id']) { $status = 'co_ordinator'; } else { $status = memberstatus($row['groupid']); } $no_members = searcharray($groupid, 'groupid', $filteredarray, 'total'); $recipes = array(); $recipes = getrecipes($row['groupid']); $result_r[] = array('reason' => 'add', 'groupid' => $groupid, 'groupname' => $groupname, 'groupimg' => $groupimg, 'grouprecipes' => $recipes, 'status' => $status, 'total' => $no_members, 'grouppending' => ''); } } foreach ($filteredarray8 as $fieldname) { $result_r[] = array('reason' => 'remove', 'dataid' => $fieldname); } } else { if ($_GET['groupsneed'] == 'joinedgroups') { $data = isset($_GET['data']) ? json_decode($_GET['data'], true) : ''; //generate the query from only fields that were altered $gene_query1 = ""; if (!empty($data)) { foreach ($data as $val) {
$result_r = $grouprecipe; } $data1 = array(); foreach ($result_r as $k => $val) { $data1[] = $val['recipeid']; } $filteredarray1 = array(); $luckyno = ''; if (!empty($filteredarray1)) { $luckyno = getRandomvalue($filteredarray1); } else { $luckyno = getRandomvalue($data1); } function searcharray($array, $value, $key) { foreach ($array as $k => $val) { if ($val[$key] == $value) { return $k; } } } $index = searcharray($result_r, $luckyno, 'recipeid'); $sql4 = mysql_query("SELECT groupid, recipename, recipeimg FROM recipes WHERE recipeid ='{$result_r[$index]['recipeid']}' LIMIT 1") or die("Database query has failed: " . mysql_error()); $row4 = mysql_fetch_array($sql4); $sql5 = mysql_query("SELECT groupname, groupimg FROM groups WHERE groupid = '{$row['groupid']}' LIMIT 1") or die("Database query has failed: " . mysql_error()); $row5 = mysql_fetch_array($sql5); $result['fastfoodname'] = $row4['recipename']; $result['fastfoodimg'] = 'uploaded_files/recipe_imgs/thumbs/' . $row4['recipeimg']; $result['fastfoodid'] = $result_r[$index]['recipeid']; echo json_encode($result); mysql_close($connection);