PHP - Simple Latitude & Longitude Help
Hello im trying to write a simple latitude and longitude script for my game. So far i have a my users and locations tables set. I have in the users table 2 entries called latitude and longitude and also in locations table 2 entries called latitude and longitude. When player finishes registering and everything is ok i placed a $new_lat and had it choose a random number between 0 and 5. I did the same with $new_long had random choose a number between 0 and 5. Now i query the the locations table (after placing a few random latitude and longitude numbers between 0 and 5) and here is where im stumped. I need assign the latitudes and longitudes that are in the locations table into possibly 2 variables and then run a check to see if the random numbers chosen match and if they do keep doing new random numbers until the randomly chosen numbers do NOT match any those in the locations table. Can someone help me out with this?
Similar TutorialsI have a string I am pulling out of a kml file to be used in google's static map image. The problem is that the longitude and latitude are in the wrong order.
$xml=simplexml_load_file($kml); //print_r($xml); $coordinates= $xml->Document->Placemark->Polygon->outerBoundaryIs->LinearRing->coordinates; $coordinates = str_replace(",0","|",$coordinates); echo $coordinates;$coordinates returns -93.93740385636626,32.5298698657008| -93.94147866742821,32.52989552832681| -93.94144945527509,32.53330102162547| -93.94975589137293,32.53335196474311| -93.94983123242544,32.52989370087431| -93.94493319136991,32.52989645540433| -93.9443121915328,32.52861950574362| -93.94419758821717,32.52736388060429| -93.94302907878635,32.52652644904565| -93.94229993303671,32.5257441308524| -93.94147580320451,32.52521094897828| -93.94137978713827,32.52261795379491| -93.93742258613195,32.5225916055261| -93.93740385636626,32.5298698657008| I need them as they are above separated by pipes to be used as a parameter in a url only I need the longitude and latitude swapped. So instead of "-93.93740385636626,32.5298698657008", I need it to read "32.5298698657008,-93.93740385636626". All of the coordinates I will be using in the future will be in the same general area as the locations above. I have downloaded Post-Google-Maps plugin and it works great. But I would like to change the default latitude and longitude and can't figure out how. I have posted this question on their support site, but I haven't received an answer, and the site doesn't seem to be actively monitored. I'm hoping there is an easy solution, and that someone on this board can help me. The plugin contains two php pages. Here is the code from post-google-map.php. Code: [Select] <?php /* Plugin Name: Post Google Map Plugin URI: http://webdevstudios.com/support/wordpress-plugins/ Description: Plugin allows posts to be linked to specific addresses and coordinates and display plotted on a Google Map. Use shortcode [google-map] to display map directly in your post/page. Map shows plots for each post with filter options and preview when hovered. <a href="options-general.php?page=post-google-map/post-google-map.php">Plugin Settings</a> | Version: 1.5.1 Author: WebDevStudios.com Author URI: http://webdevstudios.com */ $gmp_version = "1.5.1"; //hook for adding admin menus add_action('admin_menu', 'gmp_menu'); //hook for adding a new address add_action('admin_menu', 'gmp_add_new_address'); //hook for post/page custom meta box add_action('admin_menu', 'gmp_meta_box_add'); //hook for add a map to the content add_filter('the_content', 'gmp_widget'); //hook for loading widget add_action('plugins_loaded', 'gmp_widget_init'); //save/update post/page address fields from meta box function gmp_add_new_address() { $gmp_submit = $_POST["gmp_submit"]; If (isset($gmp_submit) && !empty($gmp_submit) ) { post_meta_tags(); } } //add_action('edit_post', 'post_meta_tags'); //add_action('publish_post', 'post_meta_tags'); //add_action('save_post', 'post_meta_tags'); //add_action('edit_page_form', 'post_meta_tags'); function getWords($text, $limit) { $array = explode(" ", strip_tags($text), $limit+1); if (count($array) > $limit) { unset($array[$limit]); } return implode(" ", $array); } function gmp_widget_options() { //widget options form if ($_POST['gmp_form_submit']) { update_option('gmp_widget_title', esc_attr($_POST['gmp_widget_title']) ); } //load widget title $gmp_widget_title = get_option('gmp_widget_title'); ?> <div> <label for="cc_form_title"> <strong><?php _e('Title:'); ?></strong> </label> <input style="width: 100%; margin-bottom:1em;" id="gmp_widget_title" name="gmp_widget_title" type="text" value="<?php echo htmlspecialchars(stripslashes($gmp_widget_title)); ?>" /> Setting a title will override category tabs from displaying <input type="hidden" name="gmp_form_submit" value="Submit" /> </div> <?php } function gmp_widget_init() { //widget code if ( !function_exists('register_sidebar_widget') ) return; function gmp_widget_init2() { gmp_widget('xxx'); } function gmp_widget($content) { global $wpdb; global $post; $options_arr = get_option('gmp_params'); $key = $options_arr["post_gmp_params"]; $imgpath = WP_PLUGIN_URL . '/post-google-map/markers/'; $gmp_map_type = $options_arr["post_gmp_map_type"]; $gmp_cats = $options_arr["post_gmp_cats"]; $gmp_wordpress_loop = $options_arr["gmp_wordpress_loop"]; $gmp_categories = $options_arr["gmp_categories"]; $gmp_hide = $options_arr["gmp_hide"]; $gmp_marker_max = $options_arr["gmp_marker_max"]; $gmp_marker_order = $options_arr["gmp_marker_order"]; //random number for multiple map display srand ((double) microtime( )*1000000); $rn = rand( ); //print out default categories $CT="<div class='map_cats'>"; $cat=$_GET["cat"]; $iCat_ID=$_GET["map_cat_id"]; if (($iCat_ID=="") && ($cat!="")){ $iCat_ID=$cat; } if ($gmp_cats!= ""){ $Cat_Names = explode(",", $gmp_cats); for($i = 0; $i < count($Cat_Names); $i++){ $Cat_ID = $Cat_Names[$i]; $Cat = get_cat_name($Cat_ID); if (!is_single() && $iCat_ID==""){ //$iCat_ID=$Cat_ID; } if ($i!=0){ $CT.=" | "; } $CT.="<a "; if ($Cat_ID==$iCat_ID){ $CT.="style='font-weight:bold;'"; } $CT.="href=".add_query_arg("map_cat_id", $Cat_ID).">".$Cat."</a>"; } } $CT.="</div>"; $map="var map".$rn." = new GMap2(document.getElementById('map".$rn."'));"; $map.="map".$rn.".setCenter(new GLatLng(33.7877778,-117.8522222);"; $map.="map".$rn.".setUIToDefault();"; $map.="map".$rn.".setMapType(".$gmp_map_type.");"; $map.="var bounds".$rn." = new GLatLngBounds(33.7877778,-117.8522222); "; //if viewing a single post don't load plots by categories $x=1; //shortcode if ($content!="xxx") { $map_type="short_code"; include("get_map.php"); }else{ if ($iCat_ID==""){ $y=0; if (have_posts()) : while (have_posts()) : the_post(); include("get_map.php"); endwhile; endif; } if ($iCat_ID!="" || $y==0){ $recentPosts = new WP_Query(); $recentPosts->query('showposts='.$gmp_marker_max.'&cat='.$iCat_ID); while ($recentPosts->have_posts()) : $recentPosts->the_post(); include("get_map.php"); endwhile; } } $JS.="map".$rn.".setZoom(map".$rn.".getBoundsZoomLevel(bounds".$rn."));"; $JS.="map".$rn.".setCenter(bounds".$rn.".getCenter());"; $JS.="map".$rn.".zoomOut(); "; $JS = $map.$JS; $themap = '<li id="post-google-map" class="widget widget_gmp">'; //check if widget title exists, if so use it $gmp_widget_title = get_option('gmp_widget_title'); If ($gmp_widget_title != "") { $themap.='<h2 class="title">'.$gmp_widget_title.'</h2>'; }Else{ //display the category tabs instead $themap.=$CT; } $themap.="<script src='http://maps.google.com/maps?file=api&v=1&key=".$key."' type='text/javascript'></script>"; $themap.="<body onUnload='GUnload()'>"; if ($map_type=="short_code") { $themap.="<div id='map".$rn."' style='width:100%;height:400px;'></div>"; }Else{ $themap.="<div id='map".$rn."' style='width:100%;height:200px;'></div>"; } $themap.="<div id='map-info".$rn."'></div>"; $themap.="<script type='text/javascript'>"; $themap.=$JS; $themap.="var info".$rn." = document.getElementById('map-info".$rn."');"; $themap.="info".$rn.".innerHTML = '".str_replace('[google-map]', '', $Default_HTML)."';"; $themap.="</script>"; $themap.="</li>"; if ($map_type=="short_code") { return str_replace('[google-map]', $themap, $content); }else{ echo $themap; } } if ( function_exists('wp_register_sidebar_widget') ) // fix for wordpress 2.2.1 wp_register_sidebar_widget(sanitize_title('Post Google Map' ), 'Post Google Map', 'gmp_widget_init2', array(), 1); else register_sidebar_widget('Post Google Map', 'gmp_widget_init2', 1); register_widget_control('Post Google Map', 'gmp_widget_options'); } function gmp_meta_box_add() { // Check whether the 2.5 function add_meta_box exists before adding the meta box if ( function_exists('add_meta_box') ) { add_meta_box('gmp','Post Google Map','gmp','post'); add_meta_box('gmp','Post Google Map','gmp','page'); } } function del_gmp_address($deladdy) { //delete address from a post/page If (is_numeric($deladdy)) { $id = $_GET['post']; $gmp_arr = get_post_meta($id, 'gmp_arr', false); If (is_array($gmp_arr)) { delete_post_meta($id, 'gmp_arr'); unset($gmp_arr[$deladdy]); for ($row = 0; $row <= count($gmp_arr); $row++) { If (is_array($gmp_arr[$row])) { add_post_meta($id, 'gmp_arr', $gmp_arr[$row]); } } //echo "<div id=message class=updated fade>Address deleted successfully.</div>"; $isdeleted = true; } } } function post_meta_tags() { //verify user is on the admin dashboard and at least a contributor If ( is_admin() && current_user_can('level_1') ) { global $wpdb, $alreadyran; $gmp_id = $_POST["gmp_id"]; //if post not created yet create it if ($gmp_id==0){ $title=$_POST["post_title"]; $sql = "SELECT ID FROM ".$wpdb->prefix."posts order by ID desc LIMIT 1"; $rs = mysql_query($sql); if ($rs) { while ($r = mysql_fetch_assoc($rs)) { $gmp_id=$r['ID']; } } } //save the form data from the post/page meta box if (isset($gmp_id) && !empty($gmp_id) && $alreadyran != "1") { $id = $gmp_id; $alreadyran = "1"; //get post data $gmp_long = esc_attr($_POST["gmp_long"]); $gmp_lat = esc_attr($_POST["gmp_lat"]); $gmp_address1 = esc_attr($_POST["gmp_address1"]); $gmp_address2 = esc_attr($_POST["gmp_address2"]); $gmp_city = esc_attr($_POST["gmp_city"]); $gmp_state = esc_attr($_POST["gmp_state"]); $gmp_zip = esc_attr($_POST["gmp_zip"]); $gmp_marker = esc_attr($_POST["gmp_marker"]); $gmp_title = esc_attr($_POST["gmp_title"]); $gmp_description = esc_attr($_POST["gmp_description"]); $gmp_desc_show = esc_attr($_POST["gmp_desc_show"]); //get long & lat BRM if (isset($gmp_long) && !empty($gmp_long) && isset($gmp_lat) && !empty($gmp_lat)) { }elseif (isset($gmp_address1) && !empty($gmp_address1)){ $options_arr = get_option('gmp_params'); $key = $options_arr["post_gmp_params"]; //$key = get_option('post_gmp_params'); $addressarr = array($gmp_address1, $gmp_city, $gmp_state, $gmp_zip); $address = IMPLODE(",", $addressarr); $iaddress = "http://maps.google.com/maps/geo?q=".urlencode($address)."&output=csv&key=".$key.""; //$csv = file_get_contents($iaddress); //use the WordPress HTTP API to call the Google Maps API and get coordinates $csv = wp_remote_get($iaddress); $csv = $csv["body"]; $csvSplit = split(",", $csv); $status = $csvSplit[0]; $lat = $csvSplit[2]; $lng = $csvSplit[3]; if (strcmp($status, "200") == 0){ // successful $lat = $csvSplit[2]; $lng = $csvSplit[3]; } $gmp_long=$lat; $gmp_lat=$lng; } //create an array from the post data and long/lat from Google $gmp_arr=array( "gmp_long"=>$gmp_long, "gmp_lat"=>$gmp_lat, "gmp_address1"=>$gmp_address1, "gmp_address2"=>$gmp_address2, "gmp_city"=>$gmp_city, "gmp_state"=>$gmp_state, "gmp_zip"=>$gmp_zip, "gmp_marker"=>$gmp_marker, "gmp_title"=>$gmp_title, "gmp_description"=>$gmp_description, "gmp_desc_show"=>$gmp_desc_show, ); //save address array as option gmp_arr add_post_meta($id, 'gmp_arr', $gmp_arr); //echo "<div id=message class=updated fade>Address added successfully.</div>"; } } } function gmp() { global $post; //call function to delete an address If ($_GET['deladdy'] != "" && $isdeleted != true) { //verify user is at least a contributor and on the WP dashboard to allow deleting an address If ( is_admin() && current_user_can('level_1') ) { check_admin_referer('delete-address'); $deladdy = $_GET['deladdy']; del_gmp_address($deladdy); } } $post_id = $post; if (is_object($post_id)){ $post_id = $post_id->ID; } $options_arr = get_option('gmp_params'); $gmp_api_key = $options_arr["post_gmp_params"]; $gmp_arr = get_post_meta($post_id, 'gmp_arr', false); $imgpath = WP_PLUGIN_URL . '/post-google-map/markers/'; ?> <form method="post"> <input value="<?php echo $post_id; ?>" type="hidden" name="gmp_id" /> <?php If ($gmp_api_key == "") { ?> <div class="error"> <p> <strong> Google Maps API key has not been saved. <a href="<?php echo admin_url( 'options-general.php?page=post-google-map.php' ); ?>">Enter Google Maps API Key</a> to enable post mapping. </strong> </p> </div> <?php } ?> <div style="padding-bottom:10px;">Current Saved Addresses:</div> <table cellspacing="0" cellpadding="3" width="100%" style="margin-bottom:20px"> <tr> <td colspan="2"></td> <td><strong>Address 1</strong></td> <td><strong>Address 2</strong></td> <td><strong>City</strong></td> <td><strong>State</strong></td> <td><strong>Zip</strong></td> </tr> <?php If (is_array($gmp_arr)) { $bgc==""; for ($row = 0; $row < count($gmp_arr); $row++) { if($bgc==""){ $bgc="#eeeeee"; }else{\ $bgc=""; } $gmp_action = "delete-address"; ?> <tr style="background:<?php echo $bgc;?> !important;" bgcolor="<?php echo $bgc;?>"> <td><a title="Delete Address" href="<?php echo wp_nonce_url(add_query_arg ("deladdy", $row), $gmp_action); ?>"><img width="15px" border="0" src="<?php echo WP_PLUGIN_URL . '/post-google-map/delete.png';?>"></a></td> <td><img width="25px" src="<?php echo $imgpath.$gmp_arr[$row]["gmp_marker"]; ?>"></td> <td><?php echo $gmp_arr[$row]["gmp_address1"]; ?></td> <td><?php echo $gmp_arr[$row]["gmp_address2"]; ?></td> <td><?php echo $gmp_arr[$row]["gmp_city"]; ?></td> <td><?php echo $gmp_arr[$row]["gmp_state"]; ?></td> <td><?php echo $gmp_arr[$row]["gmp_zip"]; ?></td> </tr> <tr style="background:<?php echo $bgc;?> !important;" bgcolor="<?php echo $bgc;?>"> <td colspan="2"></td> <td colspan="5"> <?php echo $gmp_arr[$row]["gmp_title"]; if ($gmp_arr[$row]["gmp_description"]!=""){ echo " - "; } echo $gmp_arr[$row]["gmp_description"]; ?> </td> </tr> <?php } }Else{ ?><tr><td colspan="6" align="center"><i>no addresses saved</i></td></tr><?php } ?> </table> <div style="padding-bottom:10px;">Enter an address or coordinates to plot this post/page on a Google Map. You can enter multiple addresses</div> <table style="margin-bottom:20px"> <tr> <th style="text-align:right;" colspan="2"> </th> </tr> <tr> <th scope="row" style="text-align:right;"><?php _e('Marker') ?></th> <td> <select name="gmp_marker"> <?php $dir = WP_PLUGIN_DIR.'/post-google-map/markers/'; $x=0; if (is_dir($dir)){ if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file<>"."&&$file<>".."){ $x=1; echo "<option value='".$file."' style='background: url(".$imgpath.$file.")no-repeat;text-indent: 30px;height:25px;'>".$file; } } closedir($handle); } } ?> </select> </td> </tr> <tr> <th scope="row" style="text-align:right;"><?php _e('Title') ?></th> <td><input value="" type="text" name="gmp_title" size="25" tabindex=91 />*If blank will use post title.</td> </tr> <tr> <th valign="top" scope="row" style="text-align:right;"><?php _e('Description') ?></th> <td><textarea name="gmp_description" style="width:300px;" tabindex=92 ></textarea><br> <input checked type="checkbox" name="gmp_desc_show"> Use excerpt or first ten words of post if excerpt is blank. </td> </tr> <tr> <th scope="row" style="text-align:right;"><?php _e('Address 1') ?></th> <td><input value="" type="text" name="gmp_address1" size="25" tabindex=93 /></td> </tr> <tr> <th scope="row" style="text-align:right;"><?php _e('Address 2') ?></th> <td><input value="" type="text" name="gmp_address2" size="25" tabindex=94 /></td> </tr> <tr> <th scope="row" style="text-align:right;"><?php _e('City') ?></th> <td><input value="" type="text" name="gmp_city" size="25" tabindex=95 /></td> </tr> <tr> <th scope="row" style="text-align:right;"><?php _e('State') ?></th> <td><input value="" type="text" name="gmp_state" size="15" tabindex=96 /></td> </tr> <tr> <th scope="row" style="text-align:right;"><?php _e('Zip Code') ?></th> <td><input value="" type="text" name="gmp_zip" size="10" tabindex=97 /></td> </tr> <tr> <th scope="row" style="text-align:right;"></th> <td>OR</td> </tr> <tr> <th scope="row" style="text-align:right;"><?php _e('Longitude') ?></th> <td><input value="" type="text" name="gmp_long" size="20" tabindex=98 /></td> </tr> <tr> <th scope="row" style="text-align:right;"><?php _e('Latitude') ?></th> <td><input value="" type="text" name="gmp_lat" size="20" tabindex=99 /></td> </tr> <tr> <th scope="row"></th> <td> <div class="submit"> <input type="submit" name="gmp_submit" value="Add Address" tabindex=100 /><br>*Post title must exist to save address </div> </td> </tr> </table> </form> <?php } function gmp_menu() { add_options_page('Post Google Map Options', 'Post Google Map', 8, __FILE__, 'gmp_options'); } //Function to save the plugin settings function gmp_update_options() { check_admin_referer('gmp_check'); //create array for storing option values $wds_gmp_arr=array( "post_gmp_params"=>esc_attr($_POST['google_api_key']), "post_gmp_cats"=>esc_attr($_POST['gmp_cats']), "post_gmp_map_type"=>esc_attr($_POST['gmp_map_type']), "gmp_wordpress_loop"=>esc_attr($_POST['gmp_wordpress_loop']), "gmp_categories"=>esc_attr($_POST['gmp_categories']), "gmp_hide"=>esc_attr($_POST['gmp_hide']), "gmp_marker_max"=>esc_attr($_POST['gmp_marker_max']), "gmp_marker_order"=>esc_attr($_POST['gmp_marker_order']), ); //save array as option update_option('gmp_params', $wds_gmp_arr); } # gmp_update_options() function gmp_options() { global $gmp_version; # Acknowledge update if ( isset($_POST['update_gmp_options']) && $_POST['update_gmp_options'] ) { gmp_update_options(); echo "<div class=\"updated\">\n" . "<p>" . "<strong>" . __('Settings saved.') . "</strong>" . "</p>\n" . "</div>\n"; } //load plugin settings $options_arr = get_option('gmp_params'); $options = $options_arr["post_gmp_params"]; $options_cats = $options_arr["post_gmp_cats"]; $options_map_type = $options_arr["post_gmp_map_type"]; $gmp_wordpress_loop = $options_arr["gmp_wordpress_loop"]; $gmp_categories = $options_arr["gmp_categories"]; $gmp_hide = $options_arr["gmp_hide"]; $gmp_marker_max = $options_arr["gmp_marker_max"]; $gmp_marker_order = $options_arr["gmp_marker_order"]; echo '<div class="wrap">'; echo '<h2>' . __('Post Google Map Settings') . '</h2>'; echo 'You must have a Google Maps API Key for this plugin to work. '; echo '<form method="post" action="">'; if ( function_exists('wp_nonce_field') ) wp_nonce_field('gmp_check'); echo '<input type="hidden" name="update_gmp_options" value="1">'; echo '<p><b>Google API Key</b> '; echo '<input type="text"' . ' name="google_api_key" id="google_api[api_key]" size="100"' . ( $options['api_key'] ? 'value="'.$options.'"' : '' ) . ' />'; echo '<p>You can obtain a free Google Maps API Key he <a href="http://code.google.com/apis/maps/signup.html" target="_blank">http://code.google.com/apis/maps/signup.html</a></p>'; ?> <b>Default Map Settings</b> <table> <tr> <td align=right>Map Type:</td> <td> <select name="gmp_map_type"> <option value="G_NORMAL_MAP" <?php If ($options_map_type == "G_NORMAL_MAP") { echo "SELECTED"; }?>>Map <option value="G_SATELLITE_MAP" <?php If ($options_map_type == "G_SATELLITE_MAP") { echo "SELECTED"; }?>>Satellite <option value="G_HYBRID_MAP" <?php If ($options_map_type == "G_HYBRID_MAP") { echo "SELECTED"; }?>>Hybrid <option value="G_DEFAULT_MAP_TYPES" <?php If ($options_map_type == "G_DEFAULT_MAP_TYPES") { echo "SELECTED"; }?>>Terrain <option value="G_PHYSICAL_MAP" <?php If ($options_map_type == "G_PHYSICAL_MAP") { echo "SELECTED"; }?>>Physical </select> </td> </tr> <!--<tr> <td valign="top" align=right>Marker View:</td> <td> <input type="checkbox" name="gmp_wordpress_loop" value="1" <?php if ($gmp_wordpress_loop==1){ ?>checked<?php } ?>>WordPress Loop <input type="checkbox" name="gmp_categories" value="1" <?php if ($gmp_categories==1){ ?>checked<?php } ?>>Categories<br>*if both are checked map will show categories if loop is empty. </td> </tr> <tr> <td align="right"></td> <td> <input type="checkbox" name="gmp_hide" value="1" <?php if ($gmp_hide==1){ ?>checked<?php } ?>>Hide map if ever empty. </td> </tr>--> <tr> <td align="right" valign="top">Category Tabs:</td> <td valign="top"> <input type="text" name="gmp_cats" value="<?php echo $options_cats; ?>">*Category IDs(ie 1,2,3) </td> </tr> <tr> <td align=right>Marker Plot Max:</td> <td> <select name="gmp_marker_max"> <?php for ($x = 0; $x <50;){ $x=$x+5; ?> <option value='<?php echo $x?>' <?php if ($gmp_marker_max==$x){ ?>selected<?php } ?>><?php echo $x?> <?php } ?> </select> *per page load </td> </tr> <!--<tr> <td align="right">Marker Order:</td> <td> <?php echo $gmp_marker_order;?> <input type="radio" name="gmp_marker_order" value="Newest" checked>Newest <input type="radio" name="gmp_marker_order" value="Random" <?php if ($gmp_marker_order=="Random"){ ?>checked<?php } ?>>Random </td> </tr>--> </table> <?php echo '<p class="submit">' . '<input type="submit"' . ' value="' . attribute_escape(__('Save Changes')) . '"' . ' />' . '</p></form>'; echo '<p>For support please visit our <a href="http://webdevstudios.com/support/wordpress-plugins/" target="_blank">WordPress Plugins</a> and <a href="http://webdevstudios.com/support/forum/" target="_blank">Support Forum</a><br>Version '. $gmp_version .' by <a href="http://webdevstudios.com/" title="WordPress Development and Design" target="_blank">WebDevStudios.com</a> | <a href="http://twitter.com/webdevstudios" target="_blank">WDS on Twitter</a></p>'; echo '</div>'; } function gmp_get_post_image($post_id, $width=0, $height=0) { $dimensions = ""; $post_id = explode(",", $post_id); foreach ($post_id as $id) { $my_query = new WP_Query('p='.$id); while ($my_query->have_posts()) : $my_query->the_post(); $attargs = array( 'numberposts' => 1, 'order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_parent' => $id); $attachments = get_children($attargs); if ($attachments) { foreach ($attachments as $attachment) { If ($width != "full" && $width != "medium" && $width != "thumb" && $width != "large") { return wp_get_attachment_image($attachment->ID, array($width, $height), false); }Else{ return wp_get_attachment_image($attachment->ID, $width, false); } } } endwhile; } } // Install/Uninstall Plugin register_activation_hook(__FILE__,'gmp_install'); //register_deactivation_hook(__FILE__,'gmp_uninstall'); //coming soon function gmp_install () { //load settings option array $options_arr = get_option('gmp_params'); //check if settings array is set //if not we need to upgrade the settings to the new array If (!is_array($options_arr) ) { //load current settings $key = get_option('post_gmp_params'); $gmp_map_type = get_option('post_gmp_map_type'); $gmp_cats = get_option('post_gmp_cats'); $gmp_wordpress_loop = get_option('gmp_wordpress_loop'); $gmp_categories = get_option('gmp_categories'); $gmp_hide = get_option('gmp_hide'); $gmp_marker_max = get_option('gmp_marker_max'); $gmp_marker_order = get_option('gmp_marker_order'); //create array for storing option values with current settings $wds_gmp_arr=array( "post_gmp_params"=>esc_attr($key), "post_gmp_cats"=>esc_attr($gmp_cats), "post_gmp_map_type"=>esc_attr($gmp_map_type), "gmp_wordpress_loop"=>esc_attr($gmp_wordpress_loop), "gmp_categories"=>esc_attr($gmp_categories), "gmp_hide"=>esc_attr($gmp_hide), "gmp_marker_max"=>esc_attr($gmp_marker_max), "gmp_marker_order"=>esc_attr($gmp_marker_order), ); //save array as option update_option('gmp_params', $wds_gmp_arr); //delete original settings delete_option('post_gmp_params'); delete_option('post_gmp_map_type'); delete_option('post_gmp_cats'); delete_option('gmp_wordpress_loop'); delete_option('gmp_categories'); delete_option('gmp_hide'); delete_option('gmp_marker_max'); delete_option('gmp_marker_order'); } } ?> Here is the code from get-map.php. Code: [Select] <?php //code to generate Google Map $post_id = $post; if (is_object($post_id)){ $post_id = $post_id->ID; $title=get_the_title($post_id->ID); $link=get_permalink($post_id->ID); } //echo "$post_id".$post_id; $gmp_arr = get_post_meta($post_id, 'gmp_arr', false); If (is_array($gmp_arr)) { for ($row = 0; $row < count($gmp_arr); $row++) { $y=$y+1; $html="<table width=100%><tr>"; $iTitle=esc_attr($gmp_arr[$row]["gmp_title"]); $iDesc=$gmp_arr[$row]["gmp_description"]; $iDesc_Show=$gmp_arr[$row]["gmp_desc_show"]; if ($iTitle==""){ $iTitle=$title; } $html.="<td colspan=2 valign=top><b><a href=".$link.">".$iTitle."</a></b>"; if ($iDesc=="" && $iDesc_Show=="on"){ if ($ran!=1){ $query = "SELECT post_excerpt,post_content FROM wp_posts WHERE ID = " . $post_id; $result = $wpdb->get_results($query, ARRAY_A); $excerpt = $result[0]['post_excerpt']; $icontent = $result[0]['post_content']; //clean up desc $icontent = esc_attr($icontent); $ran=1; } $iDesc=$excerpt; if ($iDesc==""){ $iDesc=getWords($icontent, 5); } } if ($iDesc!=""){ //echo $iDesc."<br>"; $iDesc = esc_attr($iDesc); //echo $iDesc; $html.="<br>".$iDesc; } $html.="</td></tr><tr>"; $thumb=gmp_get_post_image($post_id, 60); if ($thumb!=""){ $html.= "<td><a href=".$link.">".$thumb."</a></td>"; } $html.="<td valign=top>".$gmp_arr[$row]["gmp_address1"]."<br>".$gmp_arr[$row]["gmp_city"]." ".$gmp_arr[$row]["gmp_state"]." ".$gmp_arr[$row]["gmp_zip"]."</td></tr></table>"; //set markers if coords exist if (($gmp_arr[$row]["gmp_long"]!="") && ($gmp_arr[$row]["gmp_lat"]!="")){ $x=$x+1; $JS.="var point".$rn." = new GPoint(".$gmp_arr[$row]["gmp_lat"].", ".$gmp_arr[$row]["gmp_long"].");"; $JS.="var icon".$rn." = new GIcon();"; $JS.="icon".$rn.".image = '".$imgpath.$gmp_arr[$row]["gmp_marker"]."';"; $JS.="icon".$rn.".iconAnchor = new GPoint(15, 35);"; $JS.="var marker".$rn."".$x." = new GMarker(point".$rn.",icon".$rn.");"; $JS.="GEvent.addListener(marker".$rn."".$x.", 'click', function() {"; //$JS.="map.openInfoWindowHtml(marker".$x.".getPoint(), html".$x.");"; $JS.="location.href='".$link."';"; $JS.="});"; $JS.="GEvent.addListener(marker".$rn."".$x.", 'mouseover', function() {"; $JS.="var info".$rn." = document.getElementById('map-info".$rn."');"; $JS.="info".$rn.".innerHTML = '".str_replace('[google-map]', '', $html)."';"; if ($bm==""){ $Default_HTML=$html; $bm=1; } $JS.="});"; $JS.="map".$rn.".addOverlay(marker".$rn."".$x.");"; $JS.="bounds".$rn.".extend(marker".$rn."".$x.".getPoint());"; } } } ?> Is there something on either of these pages that I can change? Thanks so much for all your help. Hi All I've a huge database of addresses and I need to convert them to Latitude and Longtitude to enable me to do some geopositioning and distances etc. I've tried the following code, but just get a blank result Code: [Select] <?php $address="high+street+leicester+england"; $url = 'http://maps.google.com/maps/geo?q='.$address.'&output=json&oe=utf8&sensor=false&key='.$api_key; $data = @file_get_contents($url); $jsondata = json_decode($data,true); if(is_array($jsondata )&& $jsondata ['Status']['code']==200){ $lat = $jsondata ['Placemark'][0]['Point']['coordinates'][0]; $lon = $jsondata ['Placemark'][0]['Point']['coordinates'][1]; } echo "hello".$lat . " " . $lon; in my php.ini Code: [Select] ; Whether to allow the treatment of URLs (like http:// or ftp://) as files. allow_url_fopen = On ; Whether to allow include/require to open URLs (like http:// or ftp://) as files. allow_url_include = On Any ideas? Hi everyone, I'm trying to select either a class or an id using PHP Simple HTML DOM Parser with absolutely no luck. My example is very simple and seems to comply to the examples given in the manual(http://simplehtmldom.sourceforge.net/manual.htm) but it just wont work, it's driving me up the wall. Here is my example: http://schulnetz.nibis.de/db/schulen/schule.php?schulnr=94468&lschb= I think the HTML is invalid: i cannot parse it. Well i need more examples - probly i have overseen something! If anybody has a working example of Simple-html-dom-parser...i would be happy. The examples on the developersite are not very helpful. your dilbertone Hello, im very green to php and I am having trouble creating a simple log in script. Not sure why this is not working, maybe a mysql_query mistake? I am not receiving any errors but nothing gets updated in the members table and my error message to the user displays. any help is appreciated! here is my php: <?php session_start(); $errorMsg = ''; $email = ''; $pass = ''; if (isset($_POST['email'])) { $email = ($_POST['email']); $pass = ($_POST['password']); $email = stripslashes($email); $pass = stripslashes($pass); $email = strip_tags($email); $pass = strip_tags($pass); if ((!$email) || (!$pass)) { $errorMsg = '<font color="#FF0000">Please fill in both fields</font>'; }else { include 'scripts/connect_db.php'; $email = mysql_real_escape_string ($email); $pass = md5($pass); $sql = mysql_query("SELECT * FROM members WHERE email='$email' AND password='$pass'"); $log_check = mysql_num_rows($sql); if ($log_check > 0) { while($row = mysql_fetch_array($sql)) { $id = $row["id"]; $_SESSION['id']; $email = $row["email"]; $_SESSION['email']; $username = $row["username"]; $_session['username']; mysql_query("UPDATE members SET last_logged=now() WHERE id='$id' LIMIT 1"); }//Close while loop echo "You are logged in"; exit(); } else { $errorMsg = '<font color="#FF0000">Incorrect login data, please try again</font>'; } } } ?> and the form: <?php echo $errorMsg; ?> <form action="log_in.php" method="post"> Email:<br /> <input name="email" type="text" /><br /><br /> Password:<br /> <input name="password" type="password" /><br /><br /> <input name="myBtn" type="submit" value="Log In" /> </form> Hi can someone pls help, im tryin a tutorial but keep getting errors, this is the first one i get after registering. You Are Registered And Can Now Login Warning: Cannot modify header information - headers already sent by (output started at /home/aretheyh/public_html/nealeweb.com/regcheck.php:43) in /home/aretheyh/public_html/nealeweb.com/regcheck.php on line 46 I think I'm using simple xml wrong I'm trying to read strings of xml and get it to list the "attributes" in the strings but it's not working. How would I read and list the attributes of this string <Address><to>Joshua</to><from>Rockhampton</from><country>Australia</county></Address> It needs to out put a string that can be printed and look like (or something like) to:Joshua from:Rockhampton country:Australia All my code produces errors and the page just goes blank and I don't know what is wrong.l I am trying to write a PHP page that takes an XML file stored on an external server, parses it, and rewrites the data to a new XML file formatted to my liking. The feed is for events and has about 250 events to parse. The problem is that if one event has an empty node, the script will use the same event data for the node used previously. Upon research, I see that empty nodes are parsed as an empty SimpleXMLElement Object. See my code for example: XML Original: Code: [Select] <event_info> <event id="1222209"> <outcome_score><![CDATA[L, 1-0 (OT)]]></outcome_score> <quotes></quotes> <radio>102.9 FM</radio> <sched_opp><![CDATA[Toledo]]></sched_opp> </event> <event id="1222210"> <outcome_score><![CDATA[]]></outcome_score> <quotes></quotes> <radio>107.1 FM</radio> <sched_opp><![CDATA[Ohio]]></sched_opp> </event> </event_info> Output XML (note <outcome_score> on second event): Code: [Select] <event_info> <event id="1222209"> <outcome_score><![CDATA[L, 1-0 (OT)]]></outcome_score> <quotes></quotes> <radio>102.9 FM</radio> <sched_opp><![CDATA[Toledo]]></sched_opp> </event> <event id="1222210"> <outcome_score><![CDATA[L, 1-0 (OT)]]></outcome_score> <quotes></quotes> <radio>107.1 FM</radio> <sched_opp><![CDATA[Ohio]]></sched_opp> </event> </event_info> PHP code: $xml = simplexml_load_file($source); echo "<event_info>"; foreach($xml->event as $event) { echo "<event>"; if($event->outcome_score != '') { echo "<outcome_score><!CDATA[{$event->outcome_score]]></outcome_score>"; } if($event->quotes != '') { echo "<quotes><!CDATA[{$event->quotes]]></quotes>"; } } if($event->radio != '') { echo "<radio><!CDATA[{$event->radio]]></radio>"; } if($event->sched_opp != '') { echo "<sched_opp><!CDATA[{$event->sched_opp]]></sched_opp>"; } echo "</event>"; } echo "</event_info>"; Basically, whenever an event has no outcome score, the most recent outcome score is repeated for all events after. Any help would be greatly appreciated! Thanks! Code: [Select] <?php if ( $_SERVER['HTTP_REFERER'] == "http://domain.net/sub/index.php" ) { echo "true"; } else { echo "false"; } ?> is the code i'm using. /sub/index.php redirects to http://domain.net/index.php it's not seeming to work. please help sort out this bug. Have tried to do this myself all day now and i`m getting a little frustrated now. I have a contact form with a select box which can have multiple options selected, i`m using formmail.php to process the info. Problem is I have forgot how to list the values within the array and format them within the email body. $licences is the multiple select box any help would be gratefully received!! Code: [Select] <?php $name=addslashes($_POST['name']); $email=addslashes($_POST['email']); $town=addslashes($_POST['town']); $phone=addslashes($_POST['phone']); $licences=addslashes($_POST['licences']); $message=addslashes($_POST['message']); // you can specify which email you want your contact form to be emailed to here $toemail = "admin@mysite.com"; $subject = "Question : mysite.com"; $headers = "MIME-Version: 1.0\n" ."From: \"".$name."\" <".$email.">\n" ."Content-type: text/html; charset=iso-8859-1\n"; $body = "Name: ".$name."<br>\n" ."Email: ".$email."<br>\n" ."Town/City: ".$town."<br>\n" ."Phone: ".$phone."<br>\n" ."Interested in Licence/s: ".$licences."<br>\n" ."Message:<br>\n" .$message; if (!ereg("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $email)) { echo "That is not a valid email address. Please return to the" ." previous page and try again."; exit; } mail($toemail, $subject, $body, $headers); echo "Thanks for submitting your message."; ?> Please .i want php code to get metacfe thumbnail from url this is the url http://www.metacafe.com/watch/5823413/the_sinister_eyes_of_dr_orloff_movie_trailer/ php code to grab 5823413 for thumbnail links this http://www.metacafe.com/thumb/5823413.jpg Hi Guys
I'm updating my website and I'm stumped on the last section. I have a dynamic Table with various fields showing from Mysql, I use MS Access as a front end, and I have a field named Download, I enter the file location of a customers invoice and it stores the link in mysql, works perfectly. BUT, the dynamic table looks like this: Download - \users\MM4512\Invoices\Invoice23.PDF which is hyperlinked so they can download it etc.. Is there a way I can change this section from the above to a simple (Download Invoice) instead of all that text? The code used is : <td><a href="<?php echo $row_Invoices['download']; ?>" target="_blank"><?php echo $row_Invoices['download']; ?></a></td> Code: [Select] <?php //ob_start(); include "../connect.php"; Header('Cache-Control: no-cache'); Header('Pragma: no-cache'); $UserId=$_POST['UserId']; $UserId = stripslashes($UserId); $UserId = mysql_real_escape_string($UserId); $UserName=$_POST['UserName']; $UserName = stripslashes($UserName); $UserName = mysql_real_escape_string($UserName); $UserFirstName=$_POST['UserFirstName']; $UserFirstName = stripslashes($UserFirstName); $UserFirstName = mysql_real_escape_string($UserFirstName); $UserLastName=$_POST['UserLastName']; $UserLastName = stripslashes($UserLastName); $UserLastName = mysql_real_escape_string($UserLastName); $UserGender=$_POST['UserGender']; $UserGender = stripslashes($UserGender); $UserGender = mysql_real_escape_string($UserGender); $UserLink=$_POST['UserLink']; $UserLink = stripslashes($UserLink); $UserLink = mysql_real_escape_string($UserLink); $UserPicture=$_POST['UserPicture']; $UserPicture = stripslashes($UserPicture); $UserPicture = mysql_real_escape_string($UserPicture); $sql="SELECT * FROM Fb_Profile WHERE UserId='$UserId' and UserName ='$UserName' and UserFirstName ='$UserFirstName' and UserLastName ='$UserLastName' and UserGender ='$UserGender' and UserLink ='$UserLink' and UserPicture ='$UserPicture'"; $result=mysql_query($sql); $count=mysql_num_rows($result); //Lets add a first time active check 0 or 1 if 1 skip and check for update<br /> if($UserId == 'undefined') { return true; } if($count==1) { echo "&msgText=Facebook MySql Copy Successfully!\n"; return false; } else { echo "&msgText=Invalid Login!\n"; //THIS HERE IS WHAT I AM HAVING A PROBLEM WITH, IF STATEMENT STATING THAT IF $UserId IS EMPTY AND THE OTHER VARIABLES RETURN NOTHING BUT IF IS HAS A VALUE IT INSERTS //IF(!empty $UserId) $FB_Profile_Copy = mysql_query("INSERT INTO Fb_Profile(UserId,UserName,FirstName,LastName,Gender,Link,Picture) VALUES('$UserId','$UserName','$UserFirstName','$UserLastName','$UserGender','$UserLink','$UserPicture')"); $FB_BackGround_Copy = mysql_query("INSERT INTO Fb_BackGround(UserId) VALUES('$UserId')"); return false; } ?> Hello, i am newbie at PHP codes and i need help little! How to limit of chars of song? I uploaud an images and post php code! $fp_data = ereg_replace("^.*<body>","",$fp_data); $fp_data = ereg_replace("</body>.*","",$fp_data); list($currentlisteners,$status,$peak,$max,$reported,$bit,$song) = explode(",", $fp_data, 7); if($showsong == '1') { $stationinfo = ' '.$currentsong.' '.$song.' '; } if($showlisteners == '1') { $stationinfo = $stationinfo.' '.$currentlisteners.' of '.$peak.' '.$listenerlabel.' '; } } } // Include the layout for display require(JModuleHelper::getLayoutPath('mod_ngs_shoutcast')); ?> Thank you! Im trying to parse this xml but i can get it to output a simple string, can someone see what im doing wrong?? Code: [Select] $str = "<channel><item> <id>cb-uA4QHmpDxYdpgW1jPwiYsUwjBViwlinS</id> <title>Rules of Engagement - Play Ball Extended Preview - Season 5 - Episode 12</title> </item> </channel>"; $n_data = new SimpleXmlElement($str, LIBXML_NOCDATA); foreach ($n_data->channel->item as $d) { $vid = $d->id; $title = $d->title; print_r($d->title); //testing die(); //testing $arr2[] = array('vid' => $vid, 'title' => $title, 'site_id' => 10 ,'time' => 456); } The print_r() returns Code: [Select] SimpleXMLElement Object ( [0] => Rules of Engagement - Play Ball Extended Preview - Season 5 - Episode 12 ) If i simply echo $d->title it returns a string, but i need to reapply $d->title to another array as shown above Hi all - I have a simple PHP app, which I've run thru my Dreamweaver validation and a few PHP syntax validators and it comes out clean. Works perfectly in Firefox but shows a blank page in I.E. and I'm not sure why. The functionality is simple - the page shows a disclaimer, and when the user hits 'OK" it should hide the disclaimer and then display other content. Here's the URL: https://www.dca.ca.gov/webapps/bppe/annual_report.php Any ideas as to what is wrong? Thanks! Here's the code: <?php if(isset($_POST['OK'])){ ?> <h3 class="center"><a href="#a">A</a> <a href="#b">B</a> <a href="#c">C</a> <a href="#d">D</a> <a href="#e">E</a> <a href="#f">F</a> <a href="#g">G</a> <a href="#h">H</a> <a href="#i">I</a> <a href="#j">J</a> <a href="#k">K</a> <a href="#l">L</a> <a href="#m">M</a> <a href="#n">N</a> <a href="#O">O</a> <a href="#p">P</a> <a href="#q">Q</a> <a href="#r">R</a> <a href="#s">S</a> <a href="#t">T</a> <a href="#u">U</a> <a href="#v">V</a> <a href="#w">W</a> <a href="#x">X</a> <a href="#y">Y</a> <a href="#z">Z</a></h3> <h3><a name="a">A</a>:</h3> <h3><a name="b">B</a>:</h3> <h3><a name="c">C</a>:</h3> <h3><a name="d">D</a>:</h3> <h3><a name="e">E</a>:</h3> <h3><a name="f">F</a>:</h3> <h3><a name="g">G</a>:</h3> <h3><a name="h">H</a>:</h3> <h3><a name="i">I</a>:</h3> <h3><a name="j">J</a>:</h3> <h3><a name="k">K</a>:</h3> <h3><a name="l">L</a>:</h3> <h3><a name="m">M</a>:</h3> <h3><a name="n">N</a>:</h3> <h3><a name="o">O</a>:</h3> <h3><a name="p">P</a>:</h3> <h3><a name="q">Q</a>:</h3> <h3><a name="r">R</a>:</h3> <h3><a name="s">S</a>:</h3> <h3><a name="t">T</a>:</h3> <h3><a name="u">U</a>:</h3> <h3><a name="v">V</a>:</h3> <h3><a name="w">W</a>:</h3> <h3><a name="x">X</a>:</h3> <h3><a name="y">Y</a>:</h3> <h3><a name="z">Z</a>:</h3> <?php }else{ ?> <form method="post" action="annual_report.php"> <fieldset> <strong><p><strong>An Annual Report must be filed with the Bureau for Private Postsecondary Education (Bureau) by each approved institution pursuant to California Education Code (CEC) section 94934. The Institution reports the required aggregate information for all locations (main and all branches). In addition to the Annual Report, each Institution is required to submit a Performance Fact Sheet and the school catalog.</strong></p> <p><strong>The Bureau <span style="text-decoration:underline">publishes the</span> information provided in the links below <span style="text-decoration:underline">as it was submitted</span> by the institution, and does not endorse, recommend, or favor any institution whose information is published or provided</strong>.</p> <p><strong>Disclaimer of Liability</strong> <br /> The California Department of Consumer Affairs, Bureau for Private Postsecondary Education shall not be held liable for any inaccurate, altered, delayed, omitted, or misleading information, or any improper or incorrect use of the information published or provided herein, and assumes no responsibility for anyone's use of the information on any theory of liability. </p> <p><strong>Disclaimer: Links</strong> <br /> The Department of Consumer Affairs, Bureau for Private Postsecondary Education is not responsible for the contents of any off-site pages that reference, or that are referenced by, this website. The user specifically acknowledges that the Department of Consumer Affairs, Bureau for Private Postsecondary Education is not liable for any defamatory, offensive, misleading or illegal conduct of other users, links, or third parties and that the risk of injury from the foregoing rests entirely with the user. <br /> Links from this site to other sites, do not constitute an endorsement by the Department of Consumer Affairs, and are for convenience only. It is the responsibility of the user to evaluate the content and usefulness of information obtained from other sites. <br /> When you use a link to connect to another site, you are no longer on the Department of Consumer Affairs', and/or its constituent Boards’ or Bureaus’ web sites and are subject to the privacy policies and other practices of the new site. The Department of Consumer Affairs and/or its Board or Bureaus has no control over and is not responsible for the information, practices or content of these or any other sites and your participation in promotions or services of any kind with any third party found on or though this site, or your correspondence or business dealings of any kind with any third party found on or through this site are solely between you and that third party.<br /> The Department of Consumer Affairs and/or its Boards or Bureaus does not, by way of its links to other sites, endorse, adopt, recommend, promote or support products, positions, statements made or taken by parties controlling the other sites.</p> <p><strong>Choice of Law </strong><br /> Construction of the disclaimers above and resolution of disputes thereof are governed by the laws of the State of California.</p></strong> <div class="content_onecolumn"> <input type="submit" name="OK" value="OK" class="inputSubmit" /> </div> </fieldset> </form> <?php } ?> Hello, I don't have any php knowledge and am having a hard time trying to implement the following: - a drupal node is getting a numeric parameter with the URL in the following form "http://the.url/?X=123" - what I want is for the script to check if the value has been passed with the URL, then use it in a form... if the entered URL was "http://the.url" without the X variable, then use a default value of 321. <?php $_GET['X']; if (isset($X)) { print $X ; } else print "321" ?> Thanks in advance for your help. Hi again all, When i add text to my database through a form, it throws an error if i type 'wouldn't', but not if i type a word without an apostrophe. Is there a simple fix for this please peeps? Many Thanks Me@newbie.com.uk+vat |