开发者

problem printing value retrieved from MySQL Query

开发者 https://www.devze.com 2023-01-27 13:22 出处:网络
I am trying to print a value retrieved from a MySQL query with javascript. Here is the code function editVal(category){

I am trying to print a value retrieved from a MySQL query with javascript. Here is the code

function editVal(category){

            //alert(category);
            //document.getElementById("editdiv").innerHTML = '<input type = text value='+category+'>';
            <?

                $tagquery = mysql_query("Select latitude from Zones where tag = 'category'");
                while($row=mysql_fetch_array($tagquery)) { ?>
                  alert(category);
                  document.getElementById("editdiv").innerHTML = '<in开发者_如何学编程put type="text" value='"+<?=$row['latitude']?>+"'/>'; 
                <?}?>    
        }   

I know the query is working fine as I tested it before in a different form. But for some strange reason this snippet is not entering into the while loop (I tried to find it with alert function). You can have a look of the page here - http://128.233.104.33/gameview/mapv.php

I know it might be good if I would used a web service but for now just trying to solve this problem.

Any help please?


You have to make an AJAX call if you want to execute a mysql query with some parameter (here category) in query condition which depends on what you clicked.

Try to understand that, server side code has finished executing and then you clicked on the checkboxes. At this instant client side code is running and even a correct mysql query cannot run if you put it here.

Your query would actually run while the page is being generated by the server, and at that time it would not get the value of category and hence would run with category = '', hence not entering the while loop.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号