fetch data from db using javascript & php
<p>This js var has the country</p>

<pre><code>&lt;script type="text/javascript"&gt;
    var siteCmd_Country="&lt;?php echo siteCmd_Country_P ;?&gt;";  
&lt;/script&gt;

function getCountryRedirectUrl() {

        var  url_res = '#';
        if(geoCountryName != '' &amp;&amp; geoCountryName != null){

            if(geoCountryName =='United Kingdom'){
                //  window.location=Url+'uktutorsdirectory.co.uk';
                url_res = Url+'UK';//Url+'uk';
            }else if(geoCountryName =='United States'){
                url_res = Url+'usa';
            }else if(geoCountryName =='Canada'){
                url_res = Url+'canada';
            }else if(geoCountryName =='India'){
                url_res = Url+'india';
            }else if(geoCountryName =='Italy'){
                url_res = Url+'italy';
            }else if(geoCountryName =='Ireland'){
                url_res = Url+'ireland';
            }else if(geoCountryName =='Malaysia'){
                url_res = Url+'malaysia';
            }
        }
        return url_res;
}
</code></pre>

<p>this function gives the changes the url based on the geoCountryName(It is basically the country frm whr the site has been accessed)
What i want is the above method is hardcoded for every country. Now i have created an entry in db which maps country with its aliases. so i pass the geoCountryName to the query and get the aliases and append the url with alias.</p>

<p>url_res = Url+"countryAlias"; which is in JS funct and alias comes frm php-mysql</p>

<p>I tried using php but it is not working fine.below is the code</p>

<pre><code>    $conn = mysql_connect(HOSTNAME, DBUSER, DBPWD);
    mysql_select_db(DBNAME, $conn);
    mysql_query('SET CHARACTER SET utf8'); 
    $sWhere = "CountryName=".siteCmd_Country_P;
    $sql = "SELECT CountryAlias FROM `t_countrycharges`  "
            . "$sWhere ";

    $pacrs = mysql_query($sql, $conn);
    $num_rows = mysql_num_rows($pacrs);
    $row = @mysql_fetch_object($pacrs))
    $CountryAlias = $row-&gt;CountryAlias;
</code></pre>

<p>Actually the page in which all these code contains is the php page so i need to add all the code in the same page. now when i run the page with these code then the half page doesn't load and it is not showing any output. Please help me with these asap.I need to run the php on same page but there is no action or click event which can be controlled so please assist on it. All help is appreciated.</p>

<p>Thanks,
Vinay</p>