问题打印值从MySQL Query中检索 [英] problem printing value retrieved from MySQL Query

查看:115
本文介绍了问题打印值从MySQL Query中检索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用javascript打印从MySQL查询中检索的值。这里是代码

  function editVal(category){

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

$ tagquery = mysql_query(从标签='category'中选择区域的纬度);
while($ row = mysql_fetch_array($ tagquery)){?>
alert(category);
document.getElementById(editdiv)。innerHTML ='< input type =textvalue ='+<?= $ row ['latitude']?> +'/>' ;
<?}?>

我知道查询工作正常,因为我之前以不同的形式。但由于一些奇怪的原因,这段代码没有进入while循环(我试图用alert函数来查找它)。你可以在这里看看网页 - http://128.233.104.33/gameview/mapv.php



我知道如果我使用Web服务,但现在只是试图解决这个问题,那可能会很好。



有什么帮助吗?

解决方案

如果你想执行一个mysql查询,你必须进行一次AJAX调用查询条件中的某些参数(这里 category )取决于您点击的内容。

试着理解,服务器端代码已经完成执行,然后你点击了复选框。在这个即时客户端代码正在运行,甚至一个正确的mysql查询无法运行,如果你把它放在这里。



您的查询将实际运行,而页面正在生成服务器,并且当时它不会得到 category 的值,因此会以 category =''运行,因此不会进入while循环。


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 = '<input 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.

这篇关于问题打印值从MySQL Query中检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆