Jump to content

Recommended Posts

Probably a simple solution, just one I'm not sure how to do it.

 

I need the array to print out like this

 

array(
   'name'=>'Store 1',
   'address'=>'LA1'
),

 

Right now, I got it to look like this

 

Thanks in advance

Array
(
    [name] => 'Albertville Farmers Market',
    [address] => '116 Main Street Albertville, Alabama 35950'
)
,
Array
(
    [name] => 'Alexander City Downtown Market',
    [address] => 'Braod Street Alexander City, Alabama 35010'
)
,

 

How can I go about accomplishing this?

 

Here is my code

$stores = array('name'=>"'$MktName',",'address'=>"'$address'");    
echo "<pre>";
print_r($stores);    
echo "</pre>";

Link to comment
https://forums.phpfreaks.com/topic/258771-array-print/
Share on other sites

There is little practical use to it.

 

You're right. I'm trying to work with this geo coding script, and trying to add multiple items into the database at once, instead of one at a time, and it wanted the array's like that.

 

I figured out a way around it, thank you for your help.

 

Maybe you can help me out with this

 

I'm getting this error when trying to import

Fatal error: Cannot use string offset as an array in /home/redneck/public_html/markets/admin/import.php on line 44

 

This is the code

$stores = array(
        array (
          'name'=>'Albertville Farmers Market',
          'address'=>'116 Main Street Albertville Alabama 35950'
        ),
        array (
          'name'=>'Alexander City Downtown Market',
          'address'=>'Braod Street Alexander City Alabama 35010'
        ),
);

// connect to database
$db = db_connect();
$errors = array();

// import each store
foreach($stores as $k=>$v) {
// geocode address
   // $tmp = file_get_contents("http://maps.googleapis.com/maps/api/geo?q=".urlencode($v['address'])."&gl={$region}&output=xml&js?key={$google_api_key}&sensor=false");
    $tmp = file_get_contents("http://maps.google.com/maps/geo?q=".urlencode($v['address'])."&gl={$region}&output=xml&sensor=false&key={$google_api_key}");
$xml = XML2Array($tmp);
// lookup successful
if($xml['Response']['Status']['code']=='200') {
	// get latitude/longitude
	$coords = explode(',', $xml['Response']['Placemark']['Point']['coordinates']); <---- LINE 44
	// if valid
	if(isset($coords[0]) && isset($coords[1])) {
		// build data
		$data = array(
			'name'=>$v['name'],
			'address'=>$v['address'],
			'latitude'=>$coords[1],
			'longitude'=>$coords[0]
		);
		// insert store
		if( !$db->insert('stores',$data) ) {
			$errors[] = 'There was a problem inserting a store: '.$v['name'].', '.$v['address'];
		}
	}
} else {
	$errors[] = 'Address Not Found: '.$v['name'].', '.$v['address'];
}
}

Link to comment
https://forums.phpfreaks.com/topic/258771-array-print/#findComment-1326580
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.