Jump to content

RyanFitz

New Members
  • Posts

    5
  • Joined

  • Last visited

RyanFitz's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I got it I had to create a variable for each array then join them with - $payload4 = array_merge($payload, $services); it works now, displays a json array for each db row $payload1[] = array( 'LineID' => $custno, 'Qty' => $latitude, 'SetCost' => $row['Setcost'], 'MonCost' => $row['Moncost'], 'Postcode' => $row['postcode'] ); $services['services'][] = array( 'id' => $row['firstname'], 'name' => $latitude, "address" => array( "location_id" => "berlin", "lon" => $lon, "lat" => $lat ), );
  2. If I add $payload1[$record] I get this There is an extra Array ( [] => Array ( Array ( [] => Array ( [services] => Array ( [0] => Array ( [id] => ss1 [name] => visit-Joe [address] => Array ( [location_id] => 34705 [lon] => -76.43676 [lat] => 39.53483 ) [time_windows] => Array ( [0] => Array ( [earliest] => 1554805329 [latest] => 1554806329 ) ) ) )
  3. Here is what I need [services] => Array ( [0] => Array ( [id] => s-1 [name] => visit-Joe [address] => Array ( [location_id] => 13.375854_52.537338 [lon] => 13.375854 [lat] => 52.537338 ) [size] => Array ( [0] => 1 ) [time_windows] => Array ( [0] => Array ( [earliest] => 1554805329 [latest] => 1554806329 ) ) ) [1] => Array ( [id] => s-2 [name] => serve-Peter [address] => Array ( [location_id] => 13.393364_52.525851 [lon] => 13.393364 [lat] => 52.525851 ) [size] => Array ( [0] => 1 ) )
  4. I can use $payload1[$record] $record++ but it adds array to my array and my json post doesn't accept it
  5. How would I loop though this array, I need payload1 for each custno in my database, and I only get the first record. while( $row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) { $custno = $row['cust_no']; $latitude = $row['latitude']; $long= $row['longitude']; $lat = doubleval($latitude); $lon = doubleval($long); $payload1= array( "services" => array( array( "id" => "ss1", "name" => "visit-Joe", "address" => array( "location_id" => "$custno", "lon" => $lon, "lat" => $lat ), "time_windows" => array( array( "earliest" => 1554805329, "latest" => 1554806329 ) ) ), ), "configuration" => array( "routing" => array( "calc_points" => true, "snap_preventions" => array( "motorway", "trunk", "tunnel", "bridge", "ferry" ) ) ) ); } $payload3 = json_encode($payload). ',' . '{"Services":'.json_encode($array).'}'; $payload4 = array_merge($payload, $payload1); //echo json_encode($payload4); //print_r ($payload1); $data = json_decode($json); print_r ($payload1);
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.