Jump to content

Lassie

Members
  • Posts

    390
  • Joined

  • Last visited

Everything posted by Lassie

  1. Thanks for confirming that. Being a pensioner, your first option is the way i will go.
  2. I want to convert a program from what I think is Ruby to PHP as I have no knowledge of Ruby. Could someone confirm if the posted code is Ruby please and if there are any known methods to help with a conversion. Is it possible to run Ruby code within PHP? The background to this request is that I have a 3 axis accelerometer and would like to construct a pedometer. I have the data logged to a file but coding the pedometer is a challenge. I found the following ,A Pedometer in the Real World Dessy Daskalov' which does what I want but I dont follow the code. For those interested a link to the article:-http://www.aosabook.org/en/500L/a-pedometer-in-the-real-world.html Any guidance appreciated and I hope this is the right forum. class Parser attr_reader :parsed_data def self.run(data) parser = Parser.new(data) parser.parse parser end def initialize(data) @data = data end def parse @parsed_data = @data.to_s.split(';').map { |x| x.split('|') } .map { |x| x.map { |x| x.split(',').map(&:to_f) } } unless @parsed_data.map { |x| x.map(&:length).uniq }.uniq == [[3]] raise 'Bad Input. Ensure data is properly formatted.' end if @parsed_data.first.count == 1 filtered_accl = @parsed_data.map(&:flatten).transpose.map do |total_accl| grav = Filter.low_0_hz(total_accl) user = total_accl.zip(grav).map { |a, b| a - b } [user, grav] end @parsed_data = @parsed_data.length.times.map do |i| user = filtered_accl.map(&:first).map { |elem| elem[i] } grav = filtered_accl.map(&:last).map { |elem| elem[i] } [user, grav] end end end end
  3. Thank you very much. Will do.
  4. I want to modify a script that send SMS and I am using a switch statement to send different messages dependent on a condition. The original script works fine but no message is sent with my modified script. I wonder if some part is out of scope? Switch SMS.php
  5. Hi, Thanks for that. I would like to implement the the logic in PHP and I agree that I should try it myself. Thanks
  6. Hi, I am new to JS but OK in PHP. I would like to use JS code similar to this' http://www.geocachingtoolbox.com/index.php?page=dancingMen' a php program. My problem is understanding how this works. I have posted what seem to be the two key functions and my first attempt to simplify things as well as the link the above link in the hope somebody can get my thinking working in the right direction particularly in understanding the two functions. Many thanks for a starter for ten, <script type="text/javascript"> var validChars= new Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z') var validNums= new Array('0','1','2','3','4','5','6','7','8','9'); function textToIm(){ chars=document.getElementById('dancingMenText').value; splitChars=chars.split(''); newDiv=''; for(i=0; i<splitChars.length; i++){ lowerChar=splitChars[i].toLowerCase(); if (validChars.indexOf(lowerChar)>-1){ if (i+1==splitChars.length || splitChars[i+1]==' ' || splitChars[i+1]=='\n'){ newDiv+='<img src="pages/dancingMen/'+lowerChar+'v.gif" alt="'+splitChars[i]+'" title="'+splitChars[i]+'">'; }else{ newDiv+='<img src="pages/dancingMen/'+lowerChar+'.gif" alt="'+splitChars[i]+'" title="'+splitChars[i]+'">'; } }else if (validNums.indexOf(lowerChar)>-1){ newDiv+='<img src="pages/dancingMen/'+lowerChar+'.gif" alt="'+splitChars[i]+'" title="'+splitChars[i]+'">'; }else if (lowerChar!=' '){ newDiv+=splitChars[i]; } } newDiv = newDiv.replace(/\n\r?/g, '<br>'); if (chars.length==0){ newDiv=''; } document.getElementById('dancingMenDiv').innerHTML=newDiv; } function imToText(char,space){ if (space==1){ document.getElementById('dancingMenDiv').innerHTML+='<img src="pages/dancingMen/'+char+'v.gif" alt="'+char+'" title="'+char+'">'; document.getElementById('dancingMenText').value+=char+' '; }else{ document.getElementById('dancingMenDiv').innerHTML+='<img src="pages/dancingMen/'+char+'.gif" alt="'+char+'" title="'+char+'">'; document.getElementById('dancingMenText').value+=char; } } </script> index.php
  7. I am trying to build a simple program to illustrate drawdown in a pension scenario. I have a syntax error that I cant find however. Any help appreciated. <?php if(!$_POST){ ?> <table border=1> <form action="" method="post"> <tr> <td> Initial Capital: <td> <input type="text" name="amount"> <td><br> <td> Growth Rate pa: (in %) <td> <input type="text" name="rate"> <td> Period in Yrs: <td> <input type="text" name="years" maxlength="4"> <td> Yearly Drawdown: <td> <input type="text" name="drawdown" maxlength="5"> <td> <input type="submit"> </form> </table> <?php }else{ if($_POST){ $amount = $_POST['amount']; $rate = $_POST['rate']; $time = $_POST['time']; $number = $_POST['years']; $drawdown = $_POST['drawdown']; $amount2 = (float)$amount; $rate2 = (float)$rate; $drawdown2 =(float)$drawdown; $year = 1 ?> <table border=1> <tr><td> Initial Capital: <?php echo "$start" ?></td> <td>Interest: <?php echo "$rate" ?>%</td> </table> <table border=1> <tr> <th>Years</th> <th>Amount</th> <th>Remaining Capital</th> </tr> <?php while ($year <= $number) { //calculate interest and deduct drawdown $Solve_Interest = ($amount2 * $rate2 * $time) / 100; $Total_Amount = ($amount2 + $Solve_Interest); $Remaining_Capital = ($Total_Amount - $drawdown2); echo "<tr><td>"; echo $year; echo "</td><td>"; echo "<tr><td>"; echo $Solved_Interest; echo "</td><td>"; echo "<tr><td>"; echo $Remaining_Capital; echo "</td><td>"; echo "</tr>"; $year = $year + 1; $amount2 = $Remaining_Capital; } } ?>
  8. change password

  9. Right. Many thanks I have a result, now to sort out the other isssues.
  10. I am trying to make a google map with multiple markers. I have data drawn from mysql and passed to the js. I cant however get the variables for lat and lng to be recognised in my script. Any help appreciated. <script> var coords = <?php echo $output?>; console.dir(coords); </script> <div id="map" style="width: 500px; height: 400px;"></div> <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script> <script type="text/javascript"> //replace with coords, postcode, lat, lng // verify we have the right info for (var i = 0; i < coords.length; i++) { document.write('Postcode: '); document.write(coords[i].postcode); document.write('<br />'); document.write('Latitude: '); document.write(coords[i].latitude); document.write('<br />'); document.write('Longitude: '); document.write(coords[i].longitude); document.write('<br />'); } var map = new google.maps.Map(document.getElementById('map'), { zoom: 10, center: new google.maps.LatLng(0, -0), mapTypeId: google.maps.MapTypeId.ROADMAP }); var infowindow = new google.maps.InfoWindow(); var marker, i; for (i = 0; i < coords.length; i++) { marker = new google.maps.Marker({ position: new google.maps.LatLng(coords[i].latitude[1], coords[i].longitude[2]), map: map }); google.maps.event.addListener(marker, 'click', (function(marker, i) { return function() { infowindow.setContent(coords[i].postcode[0]); infowindow.open(map, marker); } })(marker, i)); } </script>
  11. Ok I understand. I will get this working and then apply that logic. Thanks very much.
  12. Thanks. So will $output = json_encode($coords); <script> var coords = <?php echo $output?>; </script> <div id="map" style="width: 500px; height: 400px;"></div> <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script> <script type="text/javascript"> //replace with coords, postcode, lat, lng var locations = [coords]; or (var i = 0; i < locations.length; i++) { document.write('Postcode: '); document.write(locations[i].postcode); document.write('<br />'); } work. thanks
  13. Ok, my problem is how to use the properties and values.
  14. I opened the developer console in chrome and it shows an array but not the values. Array[9]0: Object1: Object2: Object3: Object4: Object5: Object6: Object7: Object8: Objectlength: 9__proto__: Array[0] I have very little js expeireince so I am stuck. I want the values in an arry si can iterate through. Any suggested approaches I can try, thanks.
  15. OK. Just to be clear my (messey) code now is as follows before the google map $coords=array(); $results = $wpdb->get_results("SELECT postcode,latitude,longitude FROM uk_postcodes WHERE town = '$town'AND county='$county' ");// Get the postcode and lat and long foreach ($results as $poi) { //echo $poi->{'postcode'},$poi->{'latitude'},$poi->{'longitude'} . '<br/>'; $coords[]=$poi; //var_dump($coords); //$poi = get_object_vars($poi); // $postcode = $poi['postcode']; // $Lat = $poi['latitude']; //$Lng = $poi['longitude']; //echo $Lat; //echo $Lng; } // echo "<pre>"; //print_r($coords); //echo "</pre>"; //gives st class object //get the coords into javascript array $output = json_encode($coords); echo "<pre>"; print_r($output); echo "</pre>"; //gives st class object ?> <script> var coords = JSON.parse('<?php echo json_encode($coords) ?>'); alert(coords); //alert fails </script> Now alert (coords) gives [object}.[Object] etc having removed true ?
  16. Well, I set $coords=array(); and then ran the query and print r gives me the stdclass object as expected withthe right data. I have put the following json encode in as a test. $output = json_encode($coords); echo "<pre>"; print_r($output); echo "</pre>"; This gives {"postcode":"AB10","latitude":"57.13","longitude":"-2.11"},{"postcode":"AB11","latitude":"57.13","longitude":"-2.09"},{"postcode":"AB12","latitude":"57.10","longitude":"-2.11"},{"postcode":"AB15","latitude":"57.13","longitude":"-2.16"},{"postcode":"AB16","latitude":"57.16","longitude":"-2.15"},{"postcode":"AB21","latitude":"57.21","longitude":"-2.20"},{"postcode":"AB22","latitude":"57.18","longitude":"-2.11"},{"postcode":"AB23","latitude":"57.21","longitude":"-2.08"},{"postcode":"AB25","latitude":"57.15","longitude":"-2.11"}] I put this before the script with the json decode. Is this what I should expect and if so how to proceed?
  17. Thanks for that. I now get a js syntax error and the alert still fails. error = SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data var coords = JSON.parse('');
  18. I am getting some varaibles from the databse and want to convert my array to javascript and use the input to make a map with markers. I am cont get json encode to convert the stdclass object to a js object. My second problem is how to accees the js vars to get an array of postcodes, lats and lng. I have posted this topic before but became very confused so I am srtaring again. I have commented where I think I have the problems. Any suggestions welcome <?php //get town and county //retrieve postcodes //populate form //get town and county $town=$_GET['town']; $county=$_GET['county']; global $wpdb; $wpdb->show_errors();//debug $coords=array(); $results = $wpdb->get_results("SELECT postcode,latitude,longitude FROM uk_postcodes WHERE town = '$town'AND county='$county' ");// Get the postcode and lat and long foreach ($results as $poi) { //echo $poi->{'postcode'},$poi->{'latitude'},$poi->{'longitude'} . '<br/>'; $coords[]=$poi; //var_dump($coords); } echo "<pre>"; print_r($coords); echo "</pre>"; //gives st class object //get the coords into javascript array ?> <script> var coords = <?php echo json_encode($coords, true) ?>; alert(coords); //alert fails </script> <div id="map" style="width: 500px; height: 400px;"></div> <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script> <script type="text/javascript"> //replace with coords, postcode, lat, lng var locations = [ ['KT23', 51.28, -0.37, 4], ['KT24', 51.26, -0.42, 5], ['KT22', 51.30, -0.33, 5] ] var map = new google.maps.Map(document.getElementById('map'), { zoom: 10, center: new google.maps.LatLng(51.35, -0.26), 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>
  19. Thanks everybody. Having looked at mysql_num_rows I have amended the code as follows and this gives the expected result. if ($result) { //check if the query returned a row if(mysql_num_rows($result)){ 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 selected 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 "<p><br>Your images for $property_title </br></p>"; echo do_shortcode("[gallery include='{$images}']"); } else { echo "There are no images associated with the property $property_title "; } } else{ //query failed echo "An error occurred. Please try again"; }
  20. Ok I have changed that and I get the first error message. Is my logic right that I cant just check for a result with $result or !$result because that just says whether the query executed not that the result holds any return? My code is now if ($result) { //check if the query returned a row $row=mysql_fetch_assoc($result); if(mysql_num_rows()){ 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 selected 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 "<p><br>Your images for $property_title </br></p>"; echo do_shortcode("[gallery include='{$images}']"); } else { echo "There are no images associated with the property $property_title "; } } else{ //query failed echo "An error occurred. Please try again"; }
  21. Right I now dont have a syntax error but dont get my expected result. When I execute a valid query which I know has image attachments it fails the if($row) and gives the first error message. I will check my brackets again. My code now is if ($result) { //check if the query returned a row $row=mysql_fetch_assoc($result); if($row){ 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 "<p><br>Your images for $property_title </br></p>"; echo do_shortcode("[gallery include='{$images}']"); } else { echo "There are no images associated with the property $property_title "; } } else{ //query failed echo "An error occurred. Please try again"; }
  22. Ok, thanks that fixed that but syntax erro on my final else so I guess my {} are not right.
  23. Hi Sorry, its a syntax error after { unexpected if on if($row).
  24. I am trying to introduce some checks to 1. see if a query result is successful 2. check if the query returns a result 3.put in appropriate error messages. However the following gives me a syntax error and I cant find it. global $posts; $attachments_id=array(); global $wpdb; $result = mysql_query("SELECT post_id FROM sw_images_upload WHERE property_title = '$property_title' ");// Get the post IDs //check if there is a result if ($result) { //check if the query returned a row ($row=mysql_fetch_assoc($result)) if($row){ 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 "<p><br>Your images for $property_title </br></p>"; echo do_shortcode("[gallery include='{$images}']"); } } else { echo "There are no images associated with the property $property_title "; } } else{ //query failed echo "An error occurred. Please try again"; } Any help appreciated.
×
×
  • 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.