Jump to content

Lassie

Members
  • Posts

    390
  • Joined

  • Last visited

Everything posted by Lassie

  1. Hi, I have answered my own question.Thank you for your help. Topic is solved.
  2. Right. Thanks very much. If I want to store in a database do I need to use string?
  3. I have a SimpleXML Object and want to get the values. I have made some progress but cant work out how to iterate through the sub array values. This is the object and I want to be able to access all the values in the sub array [results]. Array ( [area_name] => SE12 [bounding_box] => SimpleXMLElement Object ( [latitude_max] => 51.458974 [latitude_min] => 51.425854 [longitude_max] => 0.052713 [longitude_min] => 0.003556 ) [country] => England [county] => London [latitude] => 51.442414 [longitude] => 0.0281345 [postcode] => SE12 [result_count] => 361 [results] => Array ( [0] => SimpleXMLElement Object ( [name] => SE12 0JB [latitude] => 51.442354 [longitude] => 0.016964 [zed_index] => 447549 ) [1] => SimpleXMLElement Object ( [name] => SE12 0BZ [latitude] => 51.433664 [longitude] => 0.022869 [zed_index] => 445747 ) [2] => SimpleXMLElement Object ( [name] => SE12 0LF [latitude] => 51.437281 [longitude] => 0.021230 [zed_index] => 445634 ) [3] => SimpleXMLElement Object ( [name] => SE12 9LG [latitude] => 51.446778 [longitude] => 0.018570 [zed_index] => 444432 ) etc I can access the first values with this $xml = new SimpleXMLElement($curl_response); $array = (array) $xml; //get values $area_name=$xml->area_name; echo $area_name .'<br/>'; //access [results] $name= $xml[results][0]->name; echo $name; This fails. I would like to iterate through all the numeric indexes and get the values to store in a database. I think i need a foreach and to assign the values to as string but cant get the construct right, Any help appreciated.
  4. Thanks for coming back. I think my problem is with php screen before I go to the javascript.
  5. Before solving the javascript challenge I need to get my result into a useable format. Each row has three cols and I need each row with the three cols for example and with vars. $co-ordinate 1=['KT17', 51.34, -0.24, 4], $co-ordinate 2=['KT18', 51.31, -0.26, 5] $co-ordinate 3 =['KT19', 51.35, -0.26, 5] $co-ordinate 1=['$postcode1', $lat1, $long1, 4],etc $co-ordinate 2=['$postcode2', 51.31, -0.26, 5] $co-ordinate 3 =['KT19', 51.35, -0.26, 5] So my problem is how to get to that from this, Any help appreciated. $i=0; while($row = mysql_fetch_assoc($result)) { $postcode[$i] = $row['postcode']; $latitude[$i] = $row['latitude']; $longitude[$i]= $row['longitude']; $i++; echo $poatcode[$i] .'<br/>'; echo$latitude[$i] .'<br/>'; echo $longitude[$i] .'<br/>'; }
  6. I am stuck trying to think of how I can use the results from my query to create php variables into a form that I can use, further in my php script or pass to a javascript to displat a map If I can pass the vars to javascript what is the best/safe way to do this. I am thinking of var postcode = "<?php echo $postcode; ?>"; var latitude = "<?php echo $latitude; ?>"; var longitude = "<?php echo $longitude; ?>"; This is the query and problem The results of the echo KT17 51.34 -0.24 KT18 51.31 -0.26 KT19 51.35 -0.26 -0.26global $wpdb; $wpdb->show_errors();//debug $result = mysql_query("SELECT postcode,latitude,longitude FROM uk_postcodes WHERE town = '$town'AND county='$county' ");// Get the postcode and lat and long while ( $row = mysql_fetch_assoc( $result ) ) { $postcode=$row['postcode']; $latitude=$row['latitude']; $longitude=$row['longitude']; echo $postcode .'<br/>'; echo $latitude .'<br/>'; echo $longitude .'<br/>'; } //put php variables into the form postcode, latitude, longitude ? //pass to javascript to draw map. var locations = [ ['KT17', 51.34, -0.24, 4], ['KT18', 51.31, -0.26, 5] ['KT19', 51.35, -0.26, 5] ]; This is the javascript <script type="text/javascript"> //need var for each var locations = [ ['KT17', 51.34, -0.24, 4], ['KT18', 51.31, -0.26, 5] ['KT19', 51.35, -0.26, 5] ]; var map = new google.maps.Map(document.getElementById('map'), { zoom: 10, center: new google.maps.LatLng(51.35, -0.26),//need var for latling as centre of map mapTypeId: google.maps.MapTypeId.ROADMAP }); var infowindow = new google.maps.InfoWindow(); var marker, i; for (i = 0; i < locations.length; i++) { marker = new google.maps.Marker({ position: new google.maps.LatLng(locations[i][1], locations[i][2]), map: map }); google.maps.event.addListener(marker, 'click', (function(marker, i) { return function() { infowindow.setContent(locations[i][0]); infowindow.open(map, marker); } })(marker, i)); } </script>
  7. Hi, I cant work out how to access a field with serialised data and extract it. Any suggestions appreciated. The table is sw_index and the fields are ID, property_title, post-code, zedindex,Date My code $wpdb->show_errors();//debug $data = serialize($array); global $wpdb; $wpdb->query( $wpdb->prepare( "INSERT INTO sw_zindex (ID,property_title,post_code,zedindex,Date)VALUES(NULL,'$property_title','$post_code','$data',NOW())")); //retrieve entry from database as test $result=$wpdb->query( "SELECT zedindex FROM sw_zindex WHERE property_title= '$property_title'"); $row=mysql_fetch_array($result); echo " "; print_r($row);// gives boolean false echo " "; extract($row); $data=unserialize($row['zedindex']);
  8. Hi, Thanks So does the uRL encode work like this. echo "".urlencode($url)."";
  9. Yes I guess so. What do you mean regarding url-encode? Also how would I then call the page? eg echo "<a target=blank href=" . $url . "</a>; Thanks for your help.
  10. OK, I have the first one working, but I am still unsure about this format:-http://www.crime-statistics.co.uk/postcode/EX23%209DZ Would the same approach work as they are not value pairs?
  11. I need to append some query strings to url's and am trying to use http_build_query. I have the following types of url to build where there are varaibles to append http://www.planningfinder.co.uk/search/near?postcode=EX23+9DZ&radius=5 http://www.crime-statistics.co.uk/postcode/EX23%209DZ http://api.zoopla.co.uk/api/v1/zed_index?area=TW14TR&output_type=outcode&api_key=1234k I have tried the last one first with the following code but I get an error unknown location form the response. Is this the right way to build query strings? $post_code=$_GET['post_code']; $key="1234k";//not a real key $outcode= "outcode"; $fields = array('area'=>$post_code, 'output_type=>$outcode, 'api_key=>$key); $url = "http://api.zoopla.co.uk/api/v1/zed_index?" . http_build_query($fields, '', "&");
  12. Thank you for the explanation. I have applied that logic and all is well.
  13. Hi, Thanks both for that. Using Ch)cu3r's input, I get the following.below which is the same as the data array that is returned. So Iguess my question is how to get those values. I am not that familiar with objects that is correct. I thought if I got the values into an array I could cylce through them, put them into php variables which I could selectively store in a database. Would there be an easier way? No sure if I should post a new topic but additionally I need to put the variable data for the curl request into the url , something like this, but it returns an error. Perhaps someone could advise me on the correct action. $key= "......";//mixed string $post_code= "TW14TR"; $url = $url= "http://api.zoopla.co.uk/api/v1/zed_index?area=' . $post_code . '&output_type=outcode&api_key=' . $Key . '; Result form amended code ( [area_name] => Hawkesley Close, Twickenham TW1 [area_url] => http://www.zoopla.co.uk/home-values/twickenham/hawkesley-close [bounding_box] => SimpleXMLElement Object ( [latitude_max] => 51.43454 [latitude_min] => 51.43454 [longitude_max] => -0.33085 [longitude_min] => -0.33085 ) [country] => England [county] => London [latitude] => 51.43454 [longitude] => -0.33085 [postcode] => TW1 [street] => Hawkesley Close [town] => Twickenham [zed_index] => 783551 [zed_index_1year] => 743182 [zed_index_2year] => 684976 [zed_index_3month] => 787538 [zed_index_3year] => 648894 [zed_index_4year] => 636067 [zed_index_5year] => 631426 [zed_index_6month] => 789645 )
  14. Hi, I dont have a an xml file as such as the object is the result of the curl call., hence $xml= new SimpleXMLElement($curl_response); So ?
  15. Hi, Thanks for that. I have add the first post code and get the first key and value, but I need all the keys and values. I would also need to use the names of the fields as the php variables. eg $country= ..... [country] => England Output below. I dont quite follow your second post yet? foreach ($xml as $key=>$value) { $array{$key} = $value; } echo " ";print_r($value);echo " "; SimpleXMLElement Object ( [0] => 800297 )
  16. I have a Curl call that returns a SimpleXMLElement Object which works. I am struggling to get the values into useable form say php variables or array. Any thoughts welcome $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_URL, 'http://api.zoopla.co.uk/api/v1/zed_index?area=TW14TR&output_type=outcode&api_key=$Key'); curl_setopt($curl, CURLOPT_HTTPGET, true); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $curl_response= curl_exec($curl); curl_close($curl); $xml= new SimpleXMLElement($curl_response); echo " ";print_r($xml);echo " "; Outputs SimpleXMLElement Object ( [area_name] => Hawkesley Close, Twickenham TW1 [area_url] => http://www.zoopla.co.uk/home-values/twickenham/hawkesley-close [bounding_box] => SimpleXMLElement Object ( [latitude_max] => 51.43454 [latitude_min] => 51.43454 [longitude_max] => -0.33085 [longitude_min] => -0.33085 ) [country] => England [county] => London [latitude] => 51.43454 [longitude] => -0.33085 [postcode] => TW1 [street] => Hawkesley Close [town] => Twickenham [zed_index] => 783551 [zed_index_1year] => 718786 [zed_index_2year] => 667084 [zed_index_3month] => 788213 [zed_index_3year] => 648497 [zed_index_4year] => 620967 [zed_index_5year] => 613178 [zed_index_6month] => 800297 )
  17. Hi All, I promised to post my solution to my problem, which is below. Please note that I am building this on wordpress and wp-pluck is a wordpress function This takes an address from a gravity form, selects all the posts for that address with image attachments puts the ids of the attachments into the gallery shortcode and displays it. //get post id from form //select all post ids for a specific address $property_title=$_GET['property']; global $posts; //$wpdb->show_errors();//debug $attachments_id=array(); //$property_title="1 hawkesley Close";//property title will be passed from front end form where property is selected. global $wpdb; $result = mysql_query("SELECT post_id FROM sw_images_upload WHERE property_title = '$property_title' ");// Get the post IDs while ( $row = mysql_fetch_assoc( $result ) ) { $attachments_id[]=$row['post_id'];//put all post ids for specific address into array } //extract post ids and cycle through image code to display images for selected property foreach ($attachments_id as $iPostID) { // Get images for all the posts for the dselected address $arrImages =& get_children('post_type=attachment&post_mime_type=image&post_parent=' . $iPostID ); }//end of foreach //select all the attachment ids from the array $imagesID= wp_list_pluck($arrImages, 'ID'); //set format for shortcode to use in wordpress [gallery include =N1.N2,N3 etc] $images=implode(" , ",$imagesID); //echo $images; echo do_shortcode("[gallery include={$images}]");
  18. Hi All, I think I have solved the problem thanks to your help. The last code I pasted does work and renders the gallery. My sql pulled the post ids and having got those I needed to pull the attachment ids. I will clen up the code and post it a little later on as I have engagements. Thanks again.
  19. Hi Thanks for your reply. I went back to my original code and modified it similar to your suggestions, which seem to be on the right track. I have pasted the results for each stage but still cant get the shortcode to work. I will test your code again. error reporting is on and no error reported. not sure where the code button is but tried inline. $attachments_id=array(); //$property_title="23 Park Road";//property title will be passed from front end form where property is selected. global $wpdb; $result = mysql_query("SELECT post_id FROM sw_images_upload WHERE property_title = '$property_title' ");// Get the post IDs while ( $row = mysql_fetch_assoc( $result ) ) { $attachments_id[]=$row['post_id'];//put all post ids for specific address into array } foreach ($attachments_id as $iPostID) { //check we have post ids echo $iPostID;//result 46649449 $args[]=$iPostID; }//end of foreach $images=implode(" , ",$args); echo $images;//result 466 , 494 , 497 echo do_shortcode("[gallery include={$images}]"); print_r($args);// result Array ( [0] => 466 [1] => 494 [2] => 497 ) // format from codex [gallery include=23,39,45]
  20. Hi, My reply to grissom crossed with your response. Thanks. code noted. The property title is passed from a form and the post ids are just to check the posts and the associated attachments are from the right property. This piece of code is just a local test to get the basisc of what I am trying to do working. I tried your code , but again get no output. Should it be $args? Tried that but no output.
  21. Hi, Thanks for that. I amended the code but dont get any output from the shotcode. echo the $string confirms it has the post ids, code so far global $wpdb; $string= ''; $result = mysql_query("SELECT post_id FROM sw_images_upload WHERE property_title = '$property_title' ");// Get the post IDs while ( $row = mysql_fetch_assoc( $result ) ) { $string .=$row['post_id'];//put all post ids for specific address into array } echo $string; // take off the last comma $string = substr($string, 0, -1); echo do_shortcode("[gallery include={$string}]");
  22. Following on from my earlier post I have a further issue and that is how to dynamically create the varaibles to pass to the shortcode. My code need to take the post ids which are retrieved from the database and put them in the gallery short code. At present this works $image1="499"; $image2="496"; //$images= $image1.$image2; // echo do_shortcode('[gallery include =' . $image1 .']'); echo do_shortcode("[gallery include={$image1},{$image2}]"); What I want to do is create the variables which maybe multiple depending on the post ids returned from the query. The query and associated code is $attachments_id=array(); global $wpdb; $result = mysql_query("SELECT post_id FROM sw_images_upload WHERE property_title = '$property_title' ");// Get the post IDs while ( $row = mysql_fetch_assoc( $result ) ) { $attachments_id[]=$row['post_id'];//put all post ids for specific address into array } foreach ($attachments_id as $iPostID) { //check we have post ids echo $iPostID; }//end of foreach //pass post ids to gallery shortcode //problem is how to create $image1 etc and put it in the shortcode? echo do_shortcode("[gallery include={$image1},{$image2}]");
  23. I am using a wordpress gallery shortcode that will display images when passed the id as so [gallery include = "499, 496] , which will display the attached images from two ids. I need the ids to be passed as variables, for example $image1= '499'; and $image2='496'; I have the following concatenation which works with one value but not two. $image1="499"; $image2="496"; $images= $image1.$image2; echo do_shortcode('[gallery include =' . $image1 .']'); //works for image1 echo do_shortcode('[gallery include =' . $image1 .'' . $image2 .']'); // only shows first image Should I expect this to work?
×
×
  • 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.