connect_error) { die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error); } $mysqli->set_charset("utf8"); $arr = array(); $tarrx = array(); $doi = $_GET['doi']; // get passed DOI $sql1 = "SELECT * FROM test.biorxiv_group_data_test WHERE group_data_doi = '$doi' limit 1"; // any entries for this DOI? $res1 = $mysqli->query($sql1); if(mysqli_num_rows($res1)){ while($row = $res1->fetch_array()) { $this_grpid = $row["group_names_id"]; // if an entry, get channel id } $sql4 = "SELECT * FROM test.biorxiv_group_names_test WHERE id = '$this_grpid' limit 1"; $res4 = $mysqli->query($sql4); while($row4 = $res4->fetch_array()) { $this_gname = $row4["group_name"]; // get name $group_status = $row4["group_status"]; // get status $group_type = $row4["group_type"]; // get type } if ($group_status == "live"){ // if channel is live we can return something $sql2 = "SELECT * FROM test.biorxiv_group_data_test, test.biorxiv_index WHERE group_data_doi = article_doi and article_url = '1' and group_names_id = '$this_grpid' order by sequence desc "; //$res3 = $mysqli->query($sql3); //while($row3 = $res3->fetch_array()) { //$this_id = $row3["id"]; //$this_doi = $row3["group_data_doi"]; //if (!($doi == $this_doi)){ //$sql2 = "SELECT * FROM test.biorxiv_index WHERE article_doi = '$this_doi' order by id desc limit 1"; $res2 = $mysqli->query($sql2); while($row2 = $res2->fetch_array()) { $this_title = $row2["article_title"]; $this_date = $row2["article_date"]; $this_doi = $row2["article_doi"]; if (!($doi == $this_doi)){ $tobj = new stdClass(); // we'll send DOI, title, channel name, and channel id $tobj->rel_doi = $this_doi; $tobj->rel_title = $this_title; $tobj->rel_gname = $this_gname; $tobj->rel_grpid = $this_grpid; $tobj->rel_date = $this_date; $tobj->rel_type = $group_type; $tarrx[] = $tobj; } } } } if (($this_grpid == 121)||($this_grpid == 159)||($this_grpid == 88)||($this_grpid == 74)){ usort($tarrx, "cmp"); //$tarrx = array_reverse($tarrx); } function cmp($a, $b) { //return strcmp($a->rel_date, $b->rel_date); return strcmp($b->rel_date, $a->rel_date); } // free the memory associated with results if (isset($res1)){ $res1->free(); } if (isset($res2)){ $res2->free(); } if (isset($res3)){ $res3->free(); } if (isset($res4)){ $res4->free(); } // close connection $mysqli->close(); $jcb = ""; if(isset($_GET['jsoncallback'])){ $jcb = $_GET["jsoncallback"]; } print $jcb . '({"rels":'.json_encode($tarrx).'})'; ?>