i having problems being able have 1 result set mysqli open @ once. in particular trying loop through select query , update columns within query after performing action.
$db = new mysqli($dbserver, $dbuser, $dbpass , $dbname); $sql = 'select uprn, postcode t_temp'; $stmt = $db->prepare($sql); $stmt -> execute(); <create array above select statement understand mysqli can hold 1 result set @ once (seems odd). unsure how such can reference uprn , postcode later> $stmt->close(); $sql = 'update t_temp set lat = ?, long = ? uprn = ?'; $stmt = $db ->prepare($sql); <loop through array built above grabbing uprn , postcode go through> $postcode = urlencode(<reference postcode in 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 struggling getting results of first query array , referencing array within loop can set values. appreciated!
don't use mysqli. use pdo instead. in latter case desired code of 1 single line:
include 'db.php'; $sql = 'select uprn, postcode t_temp'; $stmt = $db->prepare($sql); $stmt->execute(); $array = $stmt->fetchall(); // here
Comments
Post a Comment