Example #1
0
function getSqlData($arr, $data)
{
    global $colNames;
    $newData = array();
    foreach ($arr as $table => $col) {
        foreach ($col as $id) {
            $val = $colNames[$table][$id];
            if ($val == "pic") {
                $newData[$val] = getUserPic($data[$val]);
            } else {
                if ($val == "itemImageSrc") {
                    $newData[$val] = getItemPic($data[$val]);
                } else {
                    $newData[$val] = $data[$val];
                }
            }
        }
    }
    return $newData;
}
Example #2
0
 function getUsersByLocation($longitude, $latitude, $diff = 2)
 {
     $lowLon = $longitude - $diff;
     $higLon = $longitude + $diff;
     $lowLat = $latitude - $diff;
     $higLat = $latitude + $diff;
     if ($lowLat < -90) {
         $temp = $lowLat;
         $lowLat = $higLat;
         $higLat = $temp + 180;
     }
     if ($lowLon < -180) {
         $temp = $lowLon;
         $lowLon = $higLon;
         $higLon = $temp + 360;
     }
     if ($higLat > 90) {
         $temp = $higLat;
         $higLat = $lowLat;
         $lowLat = $temp - 180;
     }
     if ($higLon > 180) {
         $temp = $higLon;
         $higLon = $lowLon;
         $lowLon = $temp - 360;
     }
     $colsArray = array("item" => array(1, 4), "address" => array(3, 4, 5), "users" => array(1, 2, 4, 5, 6));
     $colStr = getSqlColumns($colsArray);
     //`users`.`uid`, `users`.`pic`, `users`.`uname`, `item`.`itemImageSrc`
     $query = "SELECT {$colStr} FROM `item`, `address`, `users` WHERE (`address`.`latitude` > {$lowLat} AND `address`.`latitude` < {$higLat}) AND (`address`.`longitude` > {$lowLon} AND `address`.`longitude` < {$higLon}) AND `item`.`aid` = `address`.`aid` AND `item`.`uid` = `users`.`uid`";
     // Long way to go over here...
     if ($result = mysql_query($query)) {
         while ($ret = mysql_fetch_array($result)) {
             $uname = $ret["uname"];
             if (!isset($this->users[$uname])) {
                 $this->users[$uname] = array("pic" => getUserPic($ret["pic"]), "fname" => $ret["fname"], "gender" => $ret["gender"], "uid" => $ret["uid"], "uname" => $ret["uname"], "owningItems" => array());
             }
             $this->users[$uname]["owningItems"][] = array("itemImageSrc" => getItemPic($ret["itemImageSrc"]), "itemId" => $ret["iid"]);
         }
     }
     return $this->users;
 }