缺少我的部分查询

时间:2011-04-30 00:59:59

标签: php mysql

好吧我正在和这个项目的某个人一起工作,他决定不完成它..但他删除了我的部分查询..任何人都可以猜测它是什么..我不是项目的这一部分的一部分.....

<?PHP 
$host = "localhost";
$user = "root";
$pass = "root";
$dbname = "ADLMaster";
$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);


$zoom = '4';
$x_offset = '-162.2200';
$y_offset = '320.2600';
$shownames = 'Yes';
$highlight = '12';

?> 

<html><head><title>Requested Planetary Information</title></head><body link="#FF0000" vlink="#FF0000" alink="#FF0000" text="#C3C3C3" bgcolor="#000000" topmargin="0" leftmargin="0">
<body>
<h2>Requested Planetary Information</h2><p><?php


$sql = "SELECT MIN(xcoord) AS min_x,
               MAX(xcoord) AS max_x,
               MIN(ycoord) AS min_y,MAX(ycoord) as max_y 
          FROM adlPlanet";
$result = mysql_query($sql);
$row = mysql_fetch_object($result);

# Create the extremes
$x_max = $row->max_x;
$x_min = $row->min_x;
$y_max = $row->max_y;
$y_min = $row->min_y;
$x_range = 800;
$y_range = 600;

$x_center = $x_max - $x_min - $x_range;
$y_center = $y_max - $y_min - $y_range;

# Max number of light years that can be jumped.
$jly = 30;


# Now calculate based on cartesian coordinates where the user clicked.
$xcoord = (($mapcoords_x + $x_min + ($x_center / 2))/$zoom) + $x_offset;
$ycoord = -((($mapcoords_y - $y_max + ($y_center / 2))/$zoom) - $y_offset);


$sSQL = <<<EOQ
   SELECT Team.Label Label,
          Planet.PlanetKey PlanetKey, 
          Planet.Climate Climate,
          Planet.Label PlanetLabel,
          Team.ShortLabel ShortLabel,
          Planet.xcoord xcoord,
          Planet.ycoord ycoord
     FROM adlPlanet Planet
LEFT JOIN adlTeam Team on Planet.TeamKey = Team.TeamKey
    WHERE ($xcoord >= xcoord - 3) 
      AND ($xcoord <= xcoord + 3) 
      AND ($ycoord >= ycoord - 3) 
      AND ($ycoord <= ycoord + 3) 
      AND **here is the missing part------------------------->**
EOQ;

echo $sSQL;
echo "<br><br>";


# (add to where if you figure out whats wrong) 
$result = mysql_query($sSQL);
$row = mysql_fetch_object($result)
?> 


<strong>Owner:</strong> 
<a href="showowner.php?own=<?php echo $row->ShortLabel; ?>"><?php echo $row['PlanetLabel'] . "(" .$row['ShortLabel'] . ")"; ?></a><br>

<strong>Planet Name:</strong> <?php print $row->PlanetLabel; ?><br>

<strong>Position:</strong> <?php print "$row->xcoord, $row->ycoord"; ?><br>

<strong>Climate:</strong> <?php print $row->Climate; ?><br>

<?php

    # Save planet information.
    $planet = new PlanetData;
    $planet->PlanetKey = $row->PlanetKey;
    $planet->PlanetLabel = $row->PlanetLabel;
    $planet->ShortLabel = $row->ShortLabel;
    $planet->xcoord = $row->xcoord;
    $planet->ycoord = $row->ycoord;



    # Find the nearest jumps.
    $select = "SQRT(POWER($planet->xcoord - xcoord, 2) + POWER($planet->ycoord - ycoord, 2)) AS distance";
    $having = "(distance <= $jly) AND (PlanetKey != $planet->PlanetKey)";
    $result = mysql_db_query("ADLMaster", "SELECT $select FROM adlPlanet HAVING ($having) ORDER BY distance");

?> 

<strong>Nearest Jumps:</strong> 

<?php
    # Print the jumps
    while ($row = mysql_fetch_object($result)) {
?> 

<a href="adl_map.php?sidereload=1&x_offset=<?php echo $row->xcoord; ?>&y_offset=<?php echo $row->ycoord; ?>&highlight=<?php echo $row->PlanetKey; ?>" target="map">
<?php
        printf ("%s (%0.2f ly)", $row->Label, $row->distance);
?>
</a>

<?php
    }

?>



</body></html>
  下面的

是数据库的示例   出问题的地方..当我   添加回来我得到零结果

Label   PlanetKey   Climate PlanetLabel ShortLabel  xcoord  ycoord
Arc-Royal Defense Cordon    1   Volcanic    A Place ARDC    -125.1800   274.8800
Arc-Royal Defense Cordon    2   Arid    Arc-Royal   ARDC    -172.1300   228.7200
Arc-Royal Defense Cordon    3   Temperate   Atocongo    ARDC    -172.3900   247.5000
Arc-Royal Defense Cordon    4   Tropical    Babaeski    ARDC    -138.7500   310.6100
Arc-Royal Defense Cordon    5   Volcanic    Bountiful Harvest   ARDC    -138.4800   263.4100
Arc-Royal Defense Cordon    6   Lunar   Deia    ARDC    -177.6000   306.4400
Arc-Royal Defense Cordon    7   Industrial  Dustball    ARDC    -105.3600   268.6200
Arc-Royal Defense Cordon    8   Tropical    Esteros ARDC    -159.6100   271.2300
Arc-Royal Defense Cordon    9   Arctic  Great X ARDC    -185.9500   290.5300
Arc-Royal Defense Cordon    10  Volcanic    Koniz   ARDC    -93.3700    262.1000
Arc-Royal Defense Cordon    11  Temperate   Kookens Pleasure Pit    ARDC    -166.6500   348.9500
Arc-Royal Defense Cordon    12  Temperate   Mkuranga    ARDC    -162.2200   320.2600
Arc-Royal Defense Cordon    13  Temperate   Morges  ARDC    -142.6600   286.1000
Arc-Royal Defense Cordon    14  Arid    New Exford  ARDC    -138.4800   245.4100
Arc-Royal Defense Cordon    15  Arctic  Pasig   ARDC    -166.6500   335.6500
Arc-Royal Defense Cordon    16  Tropical    Yeguas  ARDC    -162.4800   284.5300
Arc-Royal Defense Cordon    17  Temperate   Zanderij    ARDC    -179.6900   267.8400
Capallen Confederation  18  Temperate   Aldebaran   CAP 25.0400 -64.9400
Capallen Confederation  19  Arctic  Aldertaine  CAP 45.1200 -192.7300
Capallen Confederation  20  Volcanic    Altorra CAP -2.8700 -265.7600
Capallen Confederation  21  Industrial  Andarmax    CAP -3.3900 -389.9000
Capallen Confederation  22  Industrial  Ares    CAP 96.2400 -175.5200
Capallen Confederation  23  Arid    Bandora CAP 13.3000 -178.9100
Capallen Confederation  24  Lunar   Barras  CAP 21.1200 -357.3000
Capallen Confederation  25  Tropical    Bellatrix   CAP 54.7700 -354.6900
Capallen Confederation  26  Temperate   Bentley CAP -7.0400 -235.7600
Capallen Confederation  27  Volcanic    Betelgeuse  CAP 5.7400  -309.5700
Capallen Confederation  28  Volcanic    Bithnia CAP -19.0400    -179.9500
Capallen Confederation  29  Arid    Boardwalk   CAP -13.8200    -199.2500
Capallen Confederation  30  Arid    Bora    CAP 39.1200 -159.0900

1 个答案:

答案 0 :(得分:0)

查询似乎是正确的。我猜想问题是你传递的是一个$ xcoord和$ ycoord,它们位于所有行星所在的区域之外。此外,$ mapcoords_x和$ mapcoords_y永远不会被设置。