dpu66046 2014-06-16 14:22 采纳率: 0%
浏览 32
已采纳

从多个数组插入相同的查询

I make a mathematichs function in mysql. and give two result because it`s calculate from 2 records. this is the source :

$calculate= mysql_query("select markers_tujuan.lng,markers_tujuan.lat,open_list.lat, open_list.lng,
((SQRT((((markers_tujuan.lat-markers_tujuan.lng)*(markers_tujuan.lat-markers_tujuan.lng)) + ((open_list.lat-open_list.lng)*(open_list.lat-open_list.lng)))))+(sqrt((((markers_tujuan.lat-open_list.lat)*((markers_tujuan.lat-open_list.lat)))+((markers_tujuan.lng-open_list.lng)*((markers_tujuan.lng-open_list.lng))))))) 
as hasil
from markers_tujuan, open_list");

$op=mysql_query("select * from open_list");
$line=mysql_fetch_assoc($op);


/* fetch associative array */
while ($row = mysql_fetch_assoc($calculate)) {
    printf ("1(%s %s),(%s %s),%s <br> 
", $row["lng"], $row["lat"], $row["lat"], $row["lng"], $row["hasil"]);
        $try=mysql_query(" UPDATE open_list SET hitung = '".$row["hasil"]."' ");
    }

and the result is php running

but I didn`t understand why query in mysql updating same query

error query

  • 写回答

2条回答 默认 最新

  • doudou6050 2014-06-16 14:31
    关注

    As others have pointed out, your UPDATE statement does not have a WHERE condition. Therefore, every single row in your table will be updated, each time:

    mysql_query(" UPDATE open_list SET hitung = '".$row["hasil"]."' ");
    

    You should specify the PRIMARY KEY while updating. In this case, it is the column id (I presume). Example:

    UPDATE open_list SET hitung = 'example' WHERE id = '4'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何提取csv文件中需要的列,将其整合为一篇完整文档,并进行jieba分词(语言-python)
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?