Hallo guys, please find below my javascript and embedded PHP code…my propblem is:
1-i want to gain access to a variable should be returned from an encapsulated function, this function called is “getrownum” and it is in javascript code and below the function is highlighted in green
2- after having access to this varialbe from the forementioned function “getrownum”, i want to pass this variable to the PHP code “highlighted in red” so that i can use this variable as an index of an array of rows returned from the sql_fetch_row, in other words:
$query2 = "SELECT ObjectID FROM $table where FamilyName='$field4' and FirstName='$field5'";
$test=mysql_query($query2);
while ($array2 = mysql_fetch_row($test))
{
$array2[?> <SCRIPT LANGUAGE='javascript'> [COLOR="Red"]getrownum()[/COLOR];</SCRIPT> ];
}
echo "</tr>";
}
3- please find below the complete code:
<html>
<head>
<!-- Script Sources-->
<link rel="stylesheet" type="text/css" href="styles.css" />
<style type="text/css">
<!--@import url("styles.css")-->
</style>
<script src="http://maps.google.com/maps?file=api&v=2&key=DioG219lPJG3WTn3zmQqebsjVg" type="text/javascript"></script>
<script src="http://serverapi.arcgisonline.com/jsapi/gmaps/?v=1.6" type="text/javascript" ></script>
<script type="text/javascript">
var gmap = null;
var findTask = null;
var params = null;
var mapExtension = null;
var gOverlays = null;
var gOverlays1 = null;
var bounds = null;
var posLatLng = null;
function initialize() {
// GMap construction
gmap = new GMap2(document.getElementById('gmap'));
gmap.setCenter(new GLatLng(48.539444, 18.566389), 13); //Velke Pole
gmap.enableScrollWheelZoom();
gmap.setMapType(G_HYBRID_MAP);
gmap.addControl(new GLargeMapControl3D());
gmap.addControl(new GMapTypeControl());
gmap.enableScrollWheelZoom();
// Set the min and max scale for each layer
bounds = gmap.getBounds();
var minMapScale = 11;
var maxMapScale = 19;
// get array of map types
var mapTypes = gmap.getMapTypes();
// overwrite the getMinimumResolution() and getMaximumResolution() methods for each map type
for (var i=0; i<mapTypes.length; i++) {
mapTypes[i].getMinimumResolution = function() {return minMapScale;}
mapTypes[i].getMaximumResolution = function() {return maxMapScale;}
}
//Create MapExtension utility class
mapExtension = new esri.arcgis.gmaps.MapExtension(gmap);
// Find Task
findTask = new esri.arcgis.gmaps.FindTask("http://g-ags93.hs-karlsruhe.de/ArcGIS/rest/services/slovakei/0617final_WGS/MapServer");
}
//Function for find
function executeFind(searchText){
// Find Parameters
params = new esri.arcgis.gmaps.FindParameters();
params.layerIds = [1];
var qYear = document.getElementById("qYear").value;
if (qYear == "1")
params.searchFields = ["HsNr1850"];
else if(qYear == "2")
params.searchFields = ["HsNr1925"];
else
alert("Please Select a Year for Query")
// clear map overlays and event listeners using MapExtension removeFromMap
mapExtension.removeFromMap(gOverlays);
// set find parameters
params.contains = false;
params.searchText = searchText;;
// execute find task
findTask.execute(params, findCompleteCallback);
}
//Function for Find function results (zoom to and info window)
function findCompleteCallback(response) {
var house = response.findResults[0];
// [API Reference: ArcGIS JavaScript Extension for Google Maps](http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/gmaps/help/topics/apiref.htm#class_esri.arcgis.gmaps.FindResults)
var houseGeometry = house.feature.geometry[0];
// [API Reference: ArcGIS JavaScript Extension for Google Maps](http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/gmaps/help/topics/apiref.htm#class_esri.arcgis.gmaps.FindResult)
// [API Reference: ArcGIS JavaScript Extension for Google Maps](http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/gmaps/help/topics/apiref.htm#class_esri.arcgis.gmaps.Feature)
// Feature.geometry is an array of GPolygon objects because, Hawaii for example is an ArcGIS Polygon that has multiple rings --
// where each ring is represented as a GPolygon object in Google Maps API
var infoWindowOptions1 = {
contentTabs: [{label:"Building", content: "<b><p>House Number 1850: </b>{HsNr1850}<br/> <b>Owner: </b>{owner}<br/><b>Usage: </b>{house_usag}<br/>"},
{label:"Other", content:"<br/><b>House Number 1925: </b>{HsNr1925}"}
],
selectedTab:0
};
// center and zoom to the result
var polygonBounds = houseGeometry.getBounds();
// GPolygon.getBounds method
// [Google Maps JavaScript API V2 Reference - Google Maps JavaScript API V2 - Google Code](http://code.google.com/apis/maps/documentation/reference.html#GPolygon)
var zoomLevel = gmap.getBoundsZoomLevel(polygonBounds);
// GMap2.getBoundsZoomLevel method
// [Google Maps JavaScript API V2 Reference - Google Maps JavaScript API V2 - Google Code](http://code.google.com/apis/maps/documentation/reference.html#GMap2)
var polygonCenter = polygonBounds.getCenter();
// GLatLngBounds.getCenter method
// [Google Maps JavaScript API V2 Reference - Google Maps JavaScript API V2 - Google Code](http://code.google.com/apis/maps/documentation/reference.html#GLatLngBounds)
gmap.setCenter(polygonCenter, zoomLevel);
// add the findresutls to google map without any style
gOverlays = mapExtension.addToMap(house, null, infoWindowOptions1);
}
function ChangeColor(tableRow, highLight)
{
if (highLight)
{
tableRow.style.backgroundColor = '#7496C2';
}
else
{
tableRow.style.backgroundColor = 'white';
}
}
[COLOR="SeaGreen"][B]var arr;
var num;
function setrownum(par)
{
num=par;
}
function getrownum()
{
return num;
}
function cell()
{
var x=document.getElementById('Table2').rows[1].cells;
alert(x[9].innerHTML);
var tableElem = document.getElementById('Table2').getElementsByTagName('tr');
var numofRows=tableElem.length;
alert('Your table has ' + numofRows + ' rows.');
for (i = 0; i < tableElem.length; i++) {
tableElem[i].onclick = function() {
alert(this.rowIndex + 1);
par=this.rowIndex+1;
setrownum(par);
}
}
alert(num);
alert(getrownum());
}[/B][/COLOR]
</script>
</head>
<body onload="initialize">
<div id ="logoCont" style="background-color: #7496C2;">
<div class = "headline">Cultural Heritage Map of Velké Pole, Slovakia
</div>
</div>
<div id="topRightCont" class = "content" style="width: 415px;"><h1>Enter in Last and First Name</h1>
<form action="phpProject6Formate.php" method="post">
Family Name:<input type="text" name="field4"><br>
First Name:<input type="text" name="field5"><br>
<input type="Submit">
<div id = "credit" style="position:absolute;top: 817px;">
<table>
<tr>
<td style="vertical-align:top;">
<div class = "quicklinks" >
© Hochschule Karlsruhe - Technik und Wirtschaft 2009, <a href="impressum.html">Impressum</a>
</div>
</td>
<td style="vertical-align:top;width:15px;">
</td>
<td style= "width:225px;">
<a href="http://www.daad.de"><img src="http://www.g.hs-karlsruhe.de/geo/img/daad.gif" width="179" height="13" border="0"></a>
<a href="http://www.asiin.de"><img src="http://www.g.hs-karlsruhe.de/geo/img/asiin_klein.jpg" width="100" height="53" border="0" vertical-align="bottom" align="left"></a>
<a href="http://www.facebook.com/pages/Fakult%C3%A4t-f%C3%BCr-Geomatik-Hochschule-Karlsruhe/166116110093298"><img src="http://www.g.hs-karlsruhe.de/geo/bilder_neue/facebook-logo.png" width="100" height="38" border="0" align = "right" vertical-align="bottom"></a>
</td>
</tr>
</table>
</div>
</form>
</div>
<div id="navcontainer" style="position: absolute; top: 185px; left: 15px; width: 815px; height:25px;">
<ul id="navlist">
<li id="active">
<li><a href="HomePage.html">Home</a></li>
<li><a href="Map.html">Map</a></li>
<li><a href="History.html">History</a></li>
<li><a href="About.html">About</a></li>
</ul>
</div>
<div style="position:absolute; top: 208px; left: 15px; width: 810px; height:500px; overflow:auto; border-style:solid;border-width:3px;border-color:#7496C2">
<?php
$username="gisPrj6@localhost";/*g-ags93*/
$password="$****";
$database="sl6ova67";
$field4=$_POST['field4'];
$field5=$_POST['field5'];
$link =mysql_connect(localhost,'gisPrj6','$****');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo '';
mysql_select_db($database) or die( "Unable to select database");
$table = 'eventtable';
if (empty($field5)) {
/*echo 'FirstName is either 0, empty, or not set at all';*/
$query = "SELECT * FROM $table where FamilyName='$field4'";/*Year,Date,FamilyName,FirstName,EventType,AgeSpouse*/
}
else
{
$query = "SELECT * FROM $table where FamilyName='$field4' and FirstName='$field5'";
}
if (!$sth = mysql_query($query)) {
die("Ausführen der Abfrage <b>$query</b> nicht möglich: ".mysql_error()."\
");
}
/*else {
echo "Ausführen der Abfrage <b>$query</b> war erfolgreich.\
<br />\
";
}*/
echo "<table border='1' cellpadding='2' cellspacing='0' width='790px'><tr>";
/*echo "Table: <b>$table</b><br />\
";*/
for ($i = 0; $i < mysql_num_fields($sth); $i++) {
$col = mysql_field_name($sth,$i);
echo "<td width='13%'> <b>$col </b> </td>";
}
echo "</tr></table>";
echo "<table id='Table2' border='1' cellpadding='2' cellspacing='1' width='790px' height='300px'>";
[COLOR="Red"][B]while ($array = mysql_fetch_row($sth)) {
echo "<tr onmouseover='ChangeColor(this, true);'
onmouseout='ChangeColor(this, false);'
onclick='cell();'>";
foreach ($array as $col) {
echo "<td width='13%'>$col </td>";
}[/B][/COLOR]echo "</tr>";
}
echo "</table>";
[COLOR="Red"][B]$query2 = "SELECT ObjectID FROM $table where FamilyName='$field4' and FirstName='$field5'";
$test=mysql_query($query2);
while ($array2 = mysql_fetch_row($test)) {
$array2[?> <SCRIPT LANGUAGE='javascript'> getrownum();</SCRIPT> <?php ];
}
echo "</tr>";
}
echo "$objID";[/B][/COLOR]mysql_free_result($sth);
?>
</div>
<div id="gmap" style="position:absolute; top: 208px; left: 915px; width: 810px; height:500px; overflow:auto; border-style:solid;border-width:3px;border-color:#7496C2">
</div>
</body>
</html>
Note: i have a sharp deadline on 22/7 and this problem prevent me from proceeding…all your attempts are highly appreciated.