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”


..
...
..
var arr;
var num;

function setrownum(par)
{
 num=par;
}

[COLOR="red"]function getrownum()
{
return num;
}[/COLOR]

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);
	     
	}
	[COLOR="SandyBrown"][COLOR="Red"]alert(num);[/COLOR][/COLOR]	
    }
        	[COLOR="red"]alert(getrownum());[/COLOR]}

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.

d

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.

  1. Include a form in your html which has a input field to hold the value of num and then submit the form
<form action="" method="post">
<input type="hidden" name="num" value="" />
</form>

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&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];
		// [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&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()."\
");
} 
/*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&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.

[list][]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.[/list]

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.

This code has

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>";
  
}
 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.

  1. Include a form in your html which has a input field to hold the value of num and then submit the form
<form action="" method="post">
<input type="hidden" name="num" value="" />
</form>

Looking further - you already have a form in your html


    <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

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

which can be populate from setrownum

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

On the php script you are already picking up form variables

$field4=$_POST['field4'];
$field5=$_POST['field5'];

or extend it to pick up the num

$field4=$_POST['num'];

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

$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>";
  
}

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 :slight_smile:

ciao

As a rationalist I will go one better, and wish that you are studying hard for your exams. :slight_smile:

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.

thanks, i would never have thought that praying will replace the diligence…
i’m also rationalist :wink:

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…


<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];
		// [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="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()."\
");
} 
/*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&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>

Your do

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.

<form action="thisBackUpphpProject6Formate.php" method="get">

hallo, i tried GET method also, but PHP display the contents of any variable but not “num” as if it’s empty and in url space no change at all


<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];
		// [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';
		}
	}
	
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);
  	}
	
  </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>
           
	<input type="Submit">
	
	<form action="thisBackUpphpProject6Formate.php" method="get">
	 hidden: <input type="hidden" id="idnum" name="num" value=""><br>
	</form>

<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="$dfhg
$database="slovakia";



$field4=$_POST['field4'];
$field5=$_POST['field5'];
$num=$_GET['num'];

echo"$num";
$link =mysql_connect(localhost,'gisPrj6','$dfhg
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()."\
");
} 
/*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&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>

You have


    <form action="thisBackUpphpProject6Formate.php" method="post">
 
    Family Name:<input type="text" name="field4"><br>
    First Name:<input type="text" name="field5"><br>
           
    <input type="Submit">
    
    <form action="thisBackUpphpProject6Formate.php" method="get">
     hidden: <input type="hidden" id="idnum" name="num" value=""><br>
    </form>

The second <form> tag will terminate the first form and start a new one. num should only appear in the URL if the second form was submitted. The first form is a “post” so no parameters will appear.

Remove the second <form> tag.and for the moment change the type to “text”. Thus


    <form action="thisBackUpphpProject6Formate.php" method="get">
 
    Family Name:<input type="text" name="field4"><br>
    First Name:<input type="text" name="field5"><br>
           
    <input type="Submit">
    
     NUM: <input type="text" id="idnum" name="num" value=""><br>
    </form>

As you select a row the NUM: should be updated.

When you submit the form “num” should be transferred.

Also notice you have

echo "<tr onmouseover='ChangeColor(this, true);' 
              onmouseout='ChangeColor(this, false);' 
              onclick=''>";

Remove the onclick entirely.


<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");

	}
    //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];
		// [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';
		}
	}
	
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);
  	}
	
  </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="get">
 
    Family Name:<input type="text" name="field4"><br>
    First Name:<input type="text" name="field5"><br>
           
    <input type="Submit">
    
     NUM: <input type="text" id="idnum" name="num" value=""><br>
   

<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="$l0mn,";
$database="slovakia";



$field4=$_GET['field4'];
$field5=$_GET['field5'];
$num=$_GET['num'];

echo "$num";/*NOTHING IS DISPLAYED */

$link =mysql_connect(localhost,'gisPrj6','$lmn,4');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}

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&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='cell();'>";
   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) {
     /*print_r(array_values($array2(0)));*//*echo " $array2[$num]";*/
     echo " $array2[$num]";/*NOTHING IS DISPLAYED */
}
echo "</tr>";
 
}

echo"   $num";/*NOTHING IS DISPLAYED */
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>

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…

It’s because all of the PHP runs first, before the web page is sent to the client. Once there, the javascript then runs.

By restructuring your code so that you can use Ajax to pass data to a php page and receive a response from it.

is’t there any other way to reference an array by the value of that variable $num…
note: the array is my_sql query…