Jump to content

Recommended Posts

hi

 

i have an array that returns the longitude, latitude and timestamp of multiple users.

 

then i use a for each loop to echo the details to add markers to google maps.

 

the problem is that if one of the users has no gps position i dont want to include it it my foreach loop.

 

foreach($positions as $name => $status) {
echo 'add(jQuery(this), number += 1, "' . $name . '", "map_post.php?n=' . $name . '&u=' . $status['user_id']. '", "' . date("d-m-Y @ h:i:s",$status['timestamp']) . '", "' . $status['latitude'] . '", "' . $status['longitude'] . '", "' . $status['user_id']. '");';
}

 

how can i get the foreach to ignore the users with no data?

Link to comment
https://forums.phpfreaks.com/topic/249626-how-can-i-unset-this-array-value/
Share on other sites

how can i get the foreach to ignore the users with no data?

 

No offense, but if you can't answer that question you should consider looking for another job.

 

if ($status['latitude'] && $status['longitude']) {

 

Will skip the users with no valid latitude & longitude although you probably should put this in your query.

 

WHERE latitude > 0 && longitude > 0

 

Which negates the need for an if statement in your foreach.

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.