SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 33

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to pass a variable from encapsulated function

    Hallo, in the following code I am trying to pass the return value of the function "getrownum" to the PHP code...but the problem is, when i am trying to pass the return value of the forementioned function, i got no result..Please help and guid me.."please find my attempts highlighted below in red"
    Code:
    ..
    ...
    ..
    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());}

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Bit of an incomplete picture ... but

    1) The function cell is setting up all the click events. I am assuming that is called from an onload event. Is that so?

    If it isn't then make sure it is called after the table has been defined.

    2) "PHP code" suggests that you want num passed back to the server. If that is the case then num must be moved to an input field so it is sent to the server as part of the form data. Are you doing this.

    3) You have a number of alerts. They should be telling you everything is working as you would expect. If this is not the case when does it not.

  3. #3
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    d
    Quote Originally Posted by PhilipToop View Post
    Bit of an incomplete picture ... but

    1) The function cell is setting up all the click events. I am assuming that is called from an onload event. Is that so?
    yes
    If it isn't then make sure it is called after the table has been defined.

    2) "PHP code" suggests that you want num passed back to the server. If that is the case then num must be moved to an input field so it is sent to the server as part of the form data. Are you doing this.
    no, i want to pass the return value from function cell to the PHP code so that I can use this value to index an array.3) You have a number of alerts. They should be telling you everything is working as you would expect. If this is not the case when does it not.

  4. #4
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The javascript runs in the browser. The PHP code runs on the server. You have to pass the javascript variable num to the PHP code on the server. There are two ways of doing this.

    1. move to page which has url that includes the value of num. For example

    http://mysite.com/code.php?5

    or better (because it is extendible in a flexable way)

    http://mysite.com/code.php?num=5

    In both case the php code, code.php, can pick up the value.

    2. Include a form in your html which has a input field to hold the value of num and then submit the form

    Code HTML4Strict:
    <form action="" method="post">
    <input type="hidden" name="num" value="" />
    </form>

  5. #5
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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:
    Code JavaScript:
     
    $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:
    Code JavaScript:
    <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&amp;v=2&amp;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];
    		// [url=http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/gmaps/help/topics/apiref.htm#class_esri.arcgis.gmaps.FindResults]API Reference: ArcGIS JavaScript Extension for Google Maps[/url]
     
    		var houseGeometry = house.feature.geometry[0];
    		// [url=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[/url]
    		// [url=http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/gmaps/help/topics/apiref.htm#class_esri.arcgis.gmaps.Feature]API Reference: ArcGIS JavaScript Extension for Google Maps[/url]
    		// 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 
    		// [url=http://code.google.com/apis/maps/documentation/reference.html#GPolygon]Google Maps JavaScript API V2 Reference - Google Maps JavaScript API V2 - Google Code[/url]
     
    		var zoomLevel = gmap.getBoundsZoomLevel(polygonBounds);
    		// GMap2.getBoundsZoomLevel method
    		// [url=http://code.google.com/apis/maps/documentation/reference.html#GMap2]Google Maps JavaScript API V2 Reference - Google Maps JavaScript API V2 - Google Code[/url]
     
    		var polygonCenter = polygonBounds.getCenter();
    		// GLatLngBounds.getCenter method 
    		// [url=http://code.google.com/apis/maps/documentation/reference.html#GLatLngBounds]Google Maps JavaScript API V2 Reference - Google Maps JavaScript API V2 - Google Code[/url]
     
    		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&eacute; 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" >
    		&copy; 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()."\n");
    } 
    /*else {
       echo "Ausführen der Abfrage <b>$query</b> war erfolgreich.\n<br />\n";
    }*/
     
    echo "<table border='1' cellpadding='2' cellspacing='0' width='790px'><tr>";
     
     
    /*echo "Table: <b>$table</b><br />\n";*/
    for ($i = 0; $i < mysql_num_fields($sth); $i++) {
       $col = mysql_field_name($sth,$i);
     
       echo "<td width='13%'> <b>$col&nbsp;&nbsp;</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&nbsp;&nbsp;&nbsp;</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.

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Elpharaoh View Post
    after having access to this varialbe from the forementioned function "getrownum", i want to pass this variable to the PHP code
    • PHP code only runs on the server.
    • The server sends the web page to the client.
    • The client then processes the web page, and runs the JavaScript code.


    If you want JavaScript code to send information to the PHP code, you can do that by placing the PHP code in a separate file so that the HTML page can then request that PHP file with the appropriate JavaScript-based information.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This code has

    Code PHP:
    echo "<tr onmouseover='ChangeColor(this, true);' 
                  onmouseout='ChangeColor(this, false);' 
                  onclick='cell();'>";
       foreach ($array as $col) {
          echo "<td width='13%'>$col&nbsp;&nbsp;&nbsp;</td>";
       }[/B][/COLOR]echo "</tr>";
     
    }

    Code JavaScript:
     onclick='cell();

    Cell is your function for initialisation - it sets up event handles for click event on the table rows. So onclick is not needed. cell should be called from your initialize function.

    To return the value to num you have to do as I explain before.

    2. Include a form in your html which has a input field to hold the value of num and then submit the form

    Code HTML4Strict:
    <form action="" method="post">
    <input type="hidden" name="num" value="" />
    </form>

  8. #8
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looking further - you already have a form in your html

    Code HTML4Strict:
        <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">

    This can be extended with

    Code HTML4Strict:
    <input type="hidden" id="idnum" name="num" value="" />

    which can be populate from setrownum

    Code JavaScript:
    function setrownum(par)
    {
     document.getElementById('idnum').value = par;
     num=par;
    }

    On the php script you are already picking up form variables

    Code PHP:
    $field4=$_POST['field4'];
    $field5=$_POST['field5'];

    or extend it to pick up the num

    Code PHP:
    $field4=$_POST['num'];

    This can then be used latter where you currently have the javascript nonsense.

    Code PHP:
    $query2 = "SELECT ObjectID FROM $table where FamilyName='$field4' and FirstName='$field5'";
    $test=mysql_query($query2);
     
     
    while ($array2 = mysql_fetch_row($test)) {
     
          $array2[$num];
       }
    echo "</tr>";
     
    }

  9. #9
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Guys,
    many thanks for all of you.....
    and sorry for the late reply...actually i have nt started implementing what have u advised me yet ..because I have tomorrow an final exam and after tomorrow i have the last 2 final exams...so after tomorrowi have to start implementing these techniques..
    your contributions in providing me ways to solve my problem are really highly appreciated..pray for me to pass the exams

    ciao

  10. #10
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Elpharaoh View Post
    pray for me to pass the exams
    As a rationalist I will go one better, and wish that you are studying hard for your exams.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  11. #11
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    As a rationalist I will go one better, and wish that you are studying hard for your exams.
    thanks, i would never have thought that praying will replace the diligence...
    i'm also rationalist

  12. #12
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi,
    i have tried what you have recommended.. but i still, after passing the variable from javascript to php, i cant see the variable contents in php, although, this variable i can access its contents in javascript..

    Code JavaScript:
    <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&amp;v=2&amp;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();
    	//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");
     cell();
    	}
        //Function for find
    	function executeFind(searchText){
    	// Find Parameters
    		 params = new esri.arcgis.gmaps.FindParameters();
    		 params.layerIds = [1];
     
    		 var qYear = document.getElementById("qYear").value;
     
    		 	params.searchFields = ["ObjectID"];
     
    		// 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];
    		// [url=http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/gmaps/help/topics/apiref.htm#class_esri.arcgis.gmaps.FindResults]API Reference: ArcGIS JavaScript Extension for Google Maps[/url]
     
    		var houseGeometry = house.feature.geometry[0];
    		// [url=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[/url]
    		// [url=http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/gmaps/help/topics/apiref.htm#class_esri.arcgis.gmaps.Feature]API Reference: ArcGIS JavaScript Extension for Google Maps[/url]
    		// 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 
    		// [url=http://code.google.com/apis/maps/documentation/reference.html#GPolygon]Google Maps JavaScript API V2 Reference - Google Maps JavaScript API V2 - Google Code[/url]
     
    		var zoomLevel = gmap.getBoundsZoomLevel(polygonBounds);
    		// GMap2.getBoundsZoomLevel method
    		// [url=http://code.google.com/apis/maps/documentation/reference.html#GMap2]Google Maps JavaScript API V2 Reference - Google Maps JavaScript API V2 - Google Code[/url]
     
    		var polygonCenter = polygonBounds.getCenter();
    		// GLatLngBounds.getCenter method 
    		// [url=http://code.google.com/apis/maps/documentation/reference.html#GLatLngBounds]Google Maps JavaScript API V2 Reference - Google Maps JavaScript API V2 - Google Code[/url]
     
    		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="red"][SIZE="5"]var num;
     
    function setrownum(par)
    {
     document.getElementById('idnum').value = par;
     num=par;
     
    }
    function  getrownum()
    {
    return num;
    }
    	function cell(){
    		var tableElem = document.getElementById('Table2').getElementsByTagName('tr');
    		for (i = 0; i < tableElem.length; i++) {
    			tableElem[i].onclick = function() {
    				alert(this.rowIndex + 1);
    			par=this.rowIndex+1;
    			setrownum(par);
    		        alert(getrownum()*10);
     
    				}
     
    		}
     
    	alert(num*100);
      	}[/SIZE][/COLOR]	
      </script>
     
     
    </head>
     
     
    <body onload="initialize()">
     
    <div id ="logoCont" style="background-color: #7496C2;">
    	<div class = "headline">Cultural Heritage Map of Velk&eacute; Pole, Slovakia
     
    	</div>
    </div>
     
    <div id="topRightCont" class = "content" style="width: 415px;"><h1>Enter in Last and First Name</h1> 
    	<form action="thisBackUpphpProject6Formate.php" method="post">
     
    	Family Name:<input type="text" name="field4"><br>
    	First Name:<input type="text" name="field5"><br>
               hidden: <input type="text" id="idnum" name="num" value=""><br>
    	<input type="Submit">
     
    <div id = "credit" style="position:absolute;top: 817px;">
    	<table>
    	<tr>
    		<td style="vertical-align:top;">
    		<div class = "quicklinks" >
    		&copy; 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="$l34f45";
    $database="slovakia";
     
     
     
    [COLOR="red"][SIZE="5"]$field4=$_POST['field4'];
    $field5=$_POST['field5'];
    $num=$_post['num'];[/SIZE][/COLOR]echo"$num";
    $link =mysql_connect(localhost,'gisPrj6','$56ffhgh');
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }
    echo '';
    mysql_select_db($database) or die( "Unable to select database");
     
     
    $table = 'eventtable';
     
    echo"$num";
    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()."\n");
    } 
    /*else {
       echo "Ausführen der Abfrage <b>$query</b> war erfolgreich.\n<br />\n";
    }*/
     
    echo "<table border='1' cellpadding='2' cellspacing='0' width='790px'><tr>";
     
    /*echo "Table: <b>$table</b><br />\n";*/
    for ($i = 0; $i < mysql_num_fields($sth); $i++) {
       $col = mysql_field_name($sth,$i);
     
       echo "<td width='13%'> <b>$col&nbsp;&nbsp;</b> </td>";
    }
    echo "</tr></table>";
     
    echo "<table id='Table2' border='1' cellpadding='2' cellspacing='1' width='790px' height='300px'>";
     
     
    while ($array = mysql_fetch_row($sth)) {
    echo "<tr onmouseover='ChangeColor(this, true);' 
                  onmouseout='ChangeColor(this, false);' 
                  onclick=''>";
       foreach ($array as $col) {
     
          echo "<td width='13%'>$col&nbsp;&nbsp;&nbsp;</td>";
       }
     
    echo "</tr>";
     
    }
    echo "</table>";
     
    $query2 = "SELECT ObjectID FROM $table where FamilyName='$field4' and FirstName='$field5'";
    $test=mysql_query($query2);
     
     
    while ($array2 = mysql_fetch_row($test)) {
     
    	foreach ($array2 as $objID) {
         echo " $array2[$num]";
     
    }
    echo "</tr>";
     
    }
     
    echo"$num";
    mysql_free_result($sth);
     
    ?>
    </div>
     
     
    <div id="gmap"  style="position:absolute; top: 208px; left: 915px; width: 810px; height:500px; border-style:solid;border-width:3px;border-color:#7496C2">
    </div>
    </body>
    </html>

  13. #13
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your do

    Code PHP:
    echo"$num";

    What value is being shown?

    If on the <form> tag you change the attribute method to GET then the value passed from the browser to the server will be shown on the URL. If this is correct then the problem is server side if it is wrong then the problem is browser side.

    Code HTML4Strict:
    <form action="thisBackUpphpProject6Formate.php" method="get">

  14. #14
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    AJAX will do this. You can pass the value to a PHP script on the server and have it process directly. AJAX is the only way to do what you want.

    Research jquery ajax... clean, easy and direct.

  15. #15
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi,
    please tell me why the variable $num does not display any value when i try to display its contents..and how to display it.........

  16. #16
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Elpharaoh View Post
    hi,
    please tell me why the variable $num does not display any value when i try to display its contents..
    It's because all of the PHP runs first, before the web page is sent to the client. Once there, the javascript then runs.

    Quote Originally Posted by Elpharaoh View Post
    and how to display it.........
    By restructuring your code so that you can use Ajax to pass data to a php page and receive a response from it.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  17. #17
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is't there any other way to reference an array by the value of that variable $num....
    note: the array is my_sql query......

  18. #18
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Elpharaoh View Post
    is't there any other way to reference an array by the value of that variable $num....
    Not all in one go. No.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  19. #19
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    since it's not possible to make it in one go...can you tell me how to make it in several goes...

  20. #20
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually i have certain query as below:

    $query2 = "SELECT ObjectID FROM $table where FamilyName='$field4' and FirstName='$field5'";
    $test=mysql_query($query2);
    while ($array2 = mysql_fetch_row($test))
    {
    foreach ($array2 as $objID)
    {
    /*print_r(array_values($array2(0)));*//*echo " $array2[$num]";*/
    /*echo " $array2["."<script type='text/javascript'> num; </script>"; . "]";*/
    /*NOTHING IS DISPLAYED */
    }
    echo "</tr>";
    }

    the array "$array2" contains rows belongs to one attribute "ObjectID"..and i want to refere to this array elements depending on the value of the variable "num"..in other words, i want to use num as index, like:

    echo " $array2[$num]";

  21. #21
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Elpharaoh View Post
    actually i have certain query as below:
    It seems that the value of num and the contents of the table are quite circuitous.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  22. #22
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no, num is a variable the holds the row numbers...
    actually, there is a table contains rows based on the query retrieved from mySQL server....
    when i click certain row of that table then the variable num holds the row number..then based on the row number the variable num holds ...i want index that array "array2"

  23. #23
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Elpharaoh View Post
    no, num is a variable the holds the row numbers...
    actually, there is a table contains rows based on the query retrieved from mySQL server....
    when i click certain row of that table then the variable num holds the row number..then based on the row number the variable num holds ...i want index that array "array2"
    I'm confused. I'll have to sleep on this to see if things improve.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  24. #24
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    to be honest, i#m also confused...
    i'll try to find any solution for this

  25. #25
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Elpharaoh View Post
    no, num is a variable the holds the row numbers...
    actually, there is a table contains rows based on the query retrieved from mySQL server....
    when i click certain row of that table then the variable num holds the row number..then based on the row number the variable num holds ...i want index that array "array2"
    It would appear as though you have the table built in PHP and displayed in the browser.
    When you click on a table row, you want to get that row index and then use that value to reference data in a secondary array ($array2), right?

    The first question that comes to mind is, how is this num value to be used?
    1. as a reference in order to retrieve secondary information
    2. as a reference value to update values in a db
    3. as a reference value to retrieve more data from a db
    4. none of the above...

    For each of these scenarios, there are some distinct techniques that can be used to facilitate the requirements but you need to make some distinct changes to your code base. I can help provide that structure, but I will NOT design the functionality or debug. That is for you to do and is how you learn.

    First off, you must understand that there is NO natural intrinsic connection between PHP and JAVASCRIPT!!! NONE, NADA, ZIP, ZILCH!!! As has been stated before, PHP is code that resides on the server. It is code that will process on the web server, creating the html code pages that are sent to the client. Once at the client, JS takes over and runs code localized to the client machine. Intrinsically, PHP cannot talk directly to JS and JS cannot talk directly to PHP. LETS GET THIS STRAIGHT RIGHT NOW!!!

    As with most anything else, there is a way that they can communicate, but it requires a moderator to happen. This moderator is called AJAX. AJAX provides a means by where JS can talk to and retrieve information from a server via a transparent URL request. This is all done in the background. There is one slight caveat to this technique in that the AJAX request can only be sent to the host PC (server) and not to any other remote server (there are other ways to get this to work).

    AJAX can be put in place relatively easy using XMLHttpRequest but you will find that certain browsers (cough cough IE) can be temperamental and may not work correctly (even though MS developed this technique, go figure). Because of this, I would highly recommend you use something like JQuery for you AJAX requests. This package handles all the background cross browser overhead for you.

    Anyways... onward. A basic JQuery AJAX request JS function has the following structure:
    Code JavaScript:
    function doAjax(url, args){
            var retVal;
            retVal =   $.ajax({  
                            type: "GET",
                            url: url,
                            data: args,
                            async: false,
                        }).responseText;
            if(retVal==null || retVal=="")retval=99;
            return retVal;
        }
    This is a simple get request, you can choose any type you want, check the documentation:.

    I am going to assume you know how to get the "num" value from your table row. What I am going to show you is how to 'get' the related data from your PHP server.
    Code JavaScript:
    function rowclicked(){
       var num = getTableRowSelected();
       var other = getOtherData();
       var url = 'http://'+window.location.hostname+'/mySite/webServices/getRowData.php'; 
       var args = 'num='+num+'&other='+otherdata;
       var retData = doAjax(url,args);
       processRetVal(retVal);
    }

    Thats all you have to do to request data!!! JS will send a transparent html request to the server, and when it gets the data back, it will process it.

    Oh, by the way. You need to now write the PHP request code now.

    Simplistically, the basic structure of the PHP code is as follows:
    PHP Code:
    include_once $_SERVER['DOCUMENT_ROOT'].'requiredIncludeFile.php'
    $num 0;
    $retVal 0;

    // be smart and do escape tests on the GET data

    if(isset($_GET['num'])){
            
    $num $_GET['num'];
            if(!
    is_numeric($num)){
                
    $retVal 1;
                echo 
    $retVal;
                exit;
            }
        }
        else {
            
    $retVal 1;
            echo 
    $retVal;
            exit;
        }
    if(
    $retVal==0){
       
    // either process directly or just call a function to process and get return value(s)
       
    $retVal processNumInPHP();
    }
    // here is where the differences lie... this service page needs to ECHO the responce
    echo $retVal;
    exit; 
    One thing to keep in mind is that the return value must be text. You cannot return arrays, objects, or anythig else (JSON and XML areOK but the JQuery requester needs to be setup to manage this). Typically a preformatted string works great. You can then just dump it into your current page innerhtml or something.

    Them there's the basics. Go crazy and have fun getting it to work.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •