I'm trying to figure out a way to shorten the php code that will display every asteroid name in the NASA's neo (near earth objects) API : https://api.nasa.gov/neo/rest/v1/neo/browse?page=0
So far I'm using something like this:
echo "<h4>//The asteroid name:</h4>";
echo( $data["near_earth_objects"]["2010-05-29"][2]["name"]);
Is there a more efficient way I can configure the php code to automatically grab every "$data["near_earth_objects"]" from the api code with the nasa's link to the asteroid info?
Thank you in advance for the help
Related
I want to get the content of this 1st and 2nd webpage https://www.goodreads.com/search?utf8=%E2%9C%93&q=%D8%B3%D9%8A%D8%A7%D8%B3%D8%A9&search_type=books
and then store it in my database and then make the list is searchable.so after I googled I found that I can do it like this
$url = "https://www.goodreads.com/search?utf8=%E2%9C%93&q=%D8%B3%D9%8A%D8%A7%D8%B3%D8%A9&search_type=books";
function get_links($url){
$input = file_get_contents($url);
echo $input;
}
get_links($url);
my problem is how can I get the 2nd page content also and how can I store these books in my database to the list searchable
The answer is not that easy...
Options
Getting the pages (Not recommended)
To get a later page you can send the "page argument" in your request:
e.g.:
https://www.goodreads.com/search?page=2&q=%D8%B3%D9%8A%D8%A7%D8%B3%D8%A9&search_type=books&tab=books&utf8=%E2%9C%93
But to get the Elements into a nice structure you need to parse the HTML you get which is realy hard.
Use the API (recommended)
At https://www.goodreads.com/api/index you can find the documentation for goodreads API which returns example as response and is easily parseable.
Parse XML in PHP
If you use the API you can parse the XML-response with SimpleXML.
See example 1 & 2: http://php.net/manual/en/simplexml.examples-basic.php
Saving to database
If you are a beginner you might read some tutorials about how to use mysql with php and PDO. But you may also have a look at RedBeanPHP which is an really easy to use ORM for databases.
For getting 2nd page you will have to append on the url ?page=2
In case that you need to get other pages, you can use a for loop if you don't know how to use for loop, please google php for loop
For the database, google php mysql insert
Ok I am using drupal 7.
I need to get information out of some tables so I can read them in a iPhone app. I found out I need a php code to convert a table to json format. I need the code to go to a database "x" then to table "y". Then list entity_id and name from all the fields. This will be a read only. I don't know the first thing about php code. Can anyone point me in the right direction? Thanks
Follow the steps :-
Learns PHP :-)
learn how drupal works
Learn Drupal hooks
Drupal query.
Once you are inside drupal you dont need to coonect to drupal database, its handled by Drupal.
After this you can use hook_menu and in call back function you can return required JSON output.
Use that link in your application.
Chheers!!!
I have searched extensively for this answer. Maybe it's just too simple to be posted. Please forgive me I am missing something really obvious. I am trying to use a piece of data (number value) from a GET request (I think it is the r_object value) that I access via a URL with an API key.
I am using an external service (called "teleduino") to read data (moisture/voltage readings) from a microprocessor unit (Arduino Uno with Ethernet shield). I use my personal API key from teleduino and the teleduino service uses php GET requests (in a JSON format I think). I can load the results into an iframe on my web page using javascript, but I need to use a real variable of the data not just view it in an iframe.
For example, if I load "http://us01.proxy.teleduino.org/api/1.0/328.php?k={my-key-here}&r=getAnalogInput&pin=16" into an iframe I get something like this (when the device is online) :
{status":200,"message":"OK","response":{"result:1,"time":0.22702789306641,"values":[877]}}
The number in the square brackets is the value I need to extract as a simple variable so I can display it on the page (instead of using iframes) and also use it in mathematical calculations and other functions.
That value I need (in the square brackets after "values") is I think the "r _object" in the $GET request because when I observe the URL : r=getAnalogInput&pin=16 is the crucial data I need. (It is the number of a voltage given on pin16 of that microprocessor, which refers to the soil moisture of that plant).
I have searched extensively but cannot find out how to load that value from the get request into a variable so I can use it in the javascript on my page.
I assume it is some simple php like
moisture = $_GET[URL,"values"] ....etc etc
I am assuming it is the php r_object. And I assume I need to use php or ajax as the data is coming from an outside server (the teleduino service), so pure javascript will not work.
I am happy to write some php onto the php file of my webpage, but I do not know what that php should be.
ANY ideas would be greatly appreciated - thank you so much!!!
$_GET is for getting parameters that were passed as parameters to your PHP script, not results from a remote API. I think this is what you want:
$results = file_get_contents($url);
$data = json_decode($results, true);
$moisture = $data['response']['values'][0];
http://developers.facebook.com/docs/reference/rest/links.getStats/
Okay I have looked at the site above. but im still having some trouble.
I have formated what I need like this
http://api.facebook.com/restserver.php?method=links.getStats&urls=dogtags.com.com,http://www.petsmart.com
My only issue is I need this data to be picked by the zip code another words I only want to see how many likes are on the url http://www.petsmart.com in the zip code 66614. How can I add that variable to the xml data displaying
Thank you all help is greatly appreciated
You are using an outdated facebook API. I would recommend implementing:
http://developers.facebook.com/docs/reference/api/insights/
However, I do not believe there is any way to to look at data from a specific zip-code using the facebook insight API
I need to make an activity that displays results from a MySQL query in a line graph. Does anyone know a tutorial for beginners or sample code I could look at to accomplish this? All of my results are going to be integers of 0-10 to keep things simple if that matters.
Thanks!
This may get you started if you want to create a line graph from scratch:
How to draw a line in android
It really depends how much of this work you want to do yourself. You could probably find an open source line graph library somewhere as well.