Function arguments, return all records from database table
<p>I have a script that loops through and returns all records in the database table, code below.</p>

<p>PHP:</p>

<pre><code>for($i=0;$i&lt;$group_layer_row;$i++){
$my_layer_string="MyMap_".mb_convert_encoding(mssql_result ($rs_group_layer, $i, 0),"UTF-8","SJIS")."_".mb_convert_encoding(mssql_result ($rs_group_layer, $i, 1),"UTF-8","SJIS");
echo "var ".$my_layer_string.";\n";
}
</code></pre>

<p>What I am trying to do is turn this into an argument. Somewhat like this(this is an example, please don’t judge).</p>

<p>PHP:</p>

<pre><code>function getLayers(){
$my_layer_string="MyMap_".mb_convert_encoding(mssql_result ($rs_group_layer, $i, 0),"UTF-8","SJIS")."_".mb_convert_encoding(mssql_result ($rs_group_layer, $i, 1),"UTF-8","SJIS");
$layers="var ".$my_layer_string.";\n";
echo $layers;
}
for($i=0;$i&lt;$group_layer_row;$i++){
getLayers();
}
</code></pre>

<p>Any help on this would be very appreciated.</p>

<p>For reference I am including the sql query</p>

<pre><code>$sql= "SELECT * FROM m_group_layer WHERE group_id=\"".$_SESSION["group_id"]."\" ORDER BY display_order";
$rs_group_layer= mssql_query ($sql, $con);
$group_layer_row =mssql_num_rows($rs_group_layer);
</code></pre>

<p>EDIT: This is almost the exact same loop just with different output.</p>

<pre><code>for($i=0;$i&lt;$group_layer_row;$i++){
$my_layer_string="MyMap_".mb_convert_encoding(mssql_result ($rs_group_layer, $i, 0),"UTF-8","SJIS")."_".mb_convert_encoding(mssql_result ($rs_group_layer, $i, 1),"UTF-8","SJIS");
echo "".$my_layer_string." = new OpenLayers.Layer.WMS( \"".$my_layer_string."\",\"http://192.0.0.0/cgi-bin/mapserv.exe?map=C:/ms4w/Apache/htdocs/mapserver/data/toyama/toyama_mymap.map&amp;service=WMS&amp;SRS=EPSG:2449&amp;VERSION=1.1.1&amp;format=image/PNG&amp;layers=".$my_layer_string."\", {'layers': '".$my_layer_string."'},  {isBaseLayer: false, visibility: false,opacity:0.5,alpha:true});
map.addLayer(".$my_layer_string.");\n";
}
</code></pre>
