douyan3478 2015-01-08 12:59
浏览 36

使用PHP脚本检索Parse.com对象

I am creating a web application in which I need to retrieve objects from my Parse.com database in PHP. I can successfully retrieve the objects in JavaScript as shown below:

<script>
  var LandingSite = Parse.Object.extend("hospital");
  var query = new Parse.Query(LandingSite);
  query.find({
  success: function(results) {
    alert("Successfully retrieved " + results.length + " sites.");
    for (var i = 0; i < results.length; i++) { 
      var object = results[i];
      alert(object.id + ' - ' + object.get('name'));
    }
  },
  error: function(error) {
    alert("Error: " + error.code + " " + error.message);
  }
  });
  </script>

However, I need the code to be in PHP and the PHP script does nothing(shows no sign of it being executed). I will post the entire file just incase it is something other than just the PHP script:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
    <head>
    <script src="//www.parsecdn.com/js/parse-1.3.1.min.js"></script>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <title>LSDirectory</title>

        <style>

         body{
            background-color: burlywood;
         }

         img{
            width: 100px;
            border: 1px solid black;
            background-color: white;
         }

        </style>

        <script language = "javascript">
        Parse.initialize("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); //hidden keys
         function siteChanged( i ) {
            var siteName = document.getElementById( "landingSite" ).options[ i ].innerHTML;
            //alert( i );

            document.getElementById( "locationNumber" ).value = i;
            document.getElementById( "resetPageForm" ).submit();
         }

        </script>

    </head>
    <body>

    <h1>Landing Site Directory Data Control</h1>

 <?php
 $query = new ParseQuery("hospital");
  $results = $query->find();
  echo "Successfully retrieved " . count($results) . " sites.");
// Do something with the returned ParseObject values
for ($i = 0; $i < count($results); $i++) { 
  $object = $results[$i];
  echo $object->getObjectId() . ' - ' . $object->get('name'));
}
  # Get the recursive location number.
  $locationNumber = $_REQUEST['locationNumber'];
  if( empty( $locationNumber ) ) {
    $locationNumber = 0;
  }

  # Open the database. 
  # Pull out the locations and put in an array.
  $aLandingSites = array();

  # Fix the location of the images
  $base = 'http://www.gcap.eu/omosanya/images/';

  # This next section is hard-coded data but which would have been pulled from the database.
  $numberOfLandingSites = 5;

  $aLandingSites[1] = 'Basildon Hospital';
  $aLandingSites[2] = 'Addenbrookes Hospital';
  $aLandingSites[3] = 'Broomfield Hospital';
  $aLandingSites[4] = 'Norwich and Norfolk Hospital';
  $aLandingSites[5] = 'Royal London Hospital';

  $aBriefDescriptions[1] = 'Main landing site';
  $aBriefDescriptions[2] = 'New pad';
  $aBriefDescriptions[3] = 'Main landing site';
  $aBriefDescriptions[4] = 'Main landing site';
  $aBriefDescriptions[5] = 'Elevated helipad';

  $aElevations[1] = "101";
  $aElevations[2] = "53";
  $aElevations[3] = "88";
  $aElevations[4] = "14";
  $aElevations[5] = "310";

  $aImage1[1] = $base . "basildon1.jpg";
  $aImage2[1] = $base . "basildon2.jpg";
  $aImage3[1] = $base . "basildon3.jpg";
  $aImage4[1] = $base . "basildon4.jpg";

  $aImage1[2] = $base . "addenbrookes1.jpg";
  $aImage2[2] = $base . "addenbrookes2.jpg";
  $aImage3[2] = $base . "addenbrookes3.jpg";
  $aImage4[2] = $base . "addenbrookes4.jpg";

  $aImage1[3] = $base . "broomfield1.jpg";
  $aImage2[3] = $base . "broomfield2.jpg";
  $aImage3[3] = $base . "broomfield3.jpg";
  $aImage4[3] = $base . "broomfield4.jpg";

  $aImage1[4] = $base . "norfolk1.jpg";
  $aImage2[4] = $base . "norfolk2.jpg";
  $aImage3[4] = $base . "norfolk3.jpg";
  $aImage4[4] = $base . "norfolk4.jpg";

  $aImage1[5] = $base . "royallondon1.jpg";
  $aImage2[5] = $base . "royallondon2.jpg";
  $aImage3[5] = $base . "royallondon3.jpg";
  $aImage4[5] = $base . "royallondon4.jpg";

 ?>

 <select name="landingSite" id="landingSite" onchange="siteChanged( this.selectedIndex );">
  <option value="0">-- select --</option>

 <?php
  for( $i = 1; $i <= $numberOfLandingSites; $i++ ) {
    if( $i == $locationNumber ) {
        $j = 'selected';
    }
    else {
        $j = '';
    }

   echo "<option value=\"$i\" $j>$aLandingSites[$i]</option>";
  }
 ?>

 </select>

    <div>

     <form action="savedata.php">
     <h2>Data</h2>
     <table border="0">
      <tr>
       <td>Brief description</td><td><input type="text" name="briefDescription" value="<?php echo $aBriefDescriptions[ $locationNumber ] ?>" /></td>
      </tr>
   <tr>
    <td>Elevation</td><td><input type="text" name="elevation" value="<?php echo $aElevations[ $locationNumber ] ?>" size="3" /> ft</td>
   </tr>
   <tr>
    <td>Etc</td><td><input type="text" name="" /></td>
   </tr>
  </table>
  <input type="submit" value="save" />
  </form>

     <h2>Images</h2>
     <table border="0">
   <tr>
    <td>
     <img name="image1" src="<?php echo $aImage1[ $locationNumber ] ?>" />
     <form enctype="multipart/form-data" action="saveimage.php">
      <input type="file" name="newImage1" accept="image/jpeg" />
     </form>
    </td>
    <td>
     <img name="image2" src="<?php echo $aImage2[ $locationNumber ] ?>" />
     <form enctype="multipart/form-data" action="saveimage.php">
      <input type="file" name="newImage1" accept="image/jpeg" />
     </form>
    </td>
    <td>
     <img name="image3" src="<?php echo $aImage3[ $locationNumber ] ?>" />
     <form enctype="multipart/form-data" action="saveimage.php">
      <input type="file" name="newImage1" accept="image/jpeg" />
     </form>
    </td>
    <td>
     <img name="image4" src="<?php echo $aImage4[ $locationNumber ] ?>" />
     <form enctype="multipart/form-data" action="saveimage.php">
      <input type="file" name="newImage1" accept="image/jpeg" />
     </form>
    </td>
   </tr>
  </table>


    </div>

    <! hidden form>
    <form id="resetPageForm" action="http://www.gcap.eu/omosanya/lsdirectory.php">
     <input type="hidden" name="locationNumber" id="locationNumber" />
    </form>

    </body>
</html> 

I am new to PHP so I really do not know what is wrong. Even when I simply write

<?php 
echo "Hello world!"; 
?>

The code is not executed. Please help!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line