我正在创建一个Web应用程序,我需要在PHP中从Parse.com数据库中检索对象。我可以用JavaScript成功检索对象,如下所示:
<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>
但是,我需要代码在PHP中,PHP脚本什么都不做(没有显示它被执行的迹象)。我将发布整个文件,只是因为它不仅仅是PHP脚本:
<!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>
我是PHP的新手,所以我真的不知道出了什么问题。即使我只是写
<?php
echo "Hello world!";
?>
代码未执行。请帮忙!