dongqiang8474 2013-07-11 09:32
浏览 36
已采纳

mysqli来自更新查询中使用的选择查询

I am having problems with only being able to have one result set from mysqli open at once. In particular I am trying to loop through a select query and update columns within that query after performing an action.

$db = new mysqli($DBServer, $DBUser, $DBPass , $DBName);
$sql = 'SELECT UPRN, POSTCODE FROM T_TEMP';
$stmt = $db->prepare($sql);
$stmt -> Execute();

<Create an array from the above select statement as i understand that mysqli can 
only hold one result set at once (seems odd). I am unsure how to do this such that
i can then reference UPRN and POSTCODE later>

$stmt->Close();

$sql = 'update T_TEMP set LAT = ?, LONG = ? where UPRN = ?';
$stmt = $db ->prepare($sql);  

<loop through that array built above grabbing UPRN and POSTCODE as you go through>

$postcode = urlencode(<Reference the postcode in the array>);
$request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$postcode."&sensor=false"; 
$xml = simplexml_load_file($request_url);

$lat = round(floatval($xml->result->geometry->location->lat),4);
$long = round(floatval($xml->result->geometry->location->lng),4);

$stmt -> bind_param('ddi',$lat,$long,$UPRN);

$stmt -> Execute();

<end loop>

I am struggling with getting the results of the first query into an array and then referencing that array within the loop so i can set the values. Any help much appreciated!

  • 写回答

2条回答 默认 最新

  • dougua9328 2013-07-11 10:13
    关注

    Don't use mysqli. Use PDO instead. In this latter case this desired code would be of one single line:

    include 'db.php';
    $sql  = 'SELECT UPRN, POSTCODE FROM T_TEMP';
    $stmt = $db->prepare($sql);
    $stmt->execute();
    $array = $stmt->fetchAll(); // here you are
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思